Skip to content

Instantly share code, notes, and snippets.

Last active Nov 25, 2016
What would you like to do?
Para este taller se ocupan los paquetes: apache2, mysql-server, php7.0, libapache2-mod-php7.0 y phpmyadmin
// Conexión a la base de datos
$mysqli = new mysqli('', 'admin', 'adminadmin', 'paleteros');
// Si la conexión falla
if ($mysqli->connect_errno) {
// Imprime el error
echo "Error: " . $mysqli->connect_error . "\n";
} else {
if ($_POST['nombre'] && $_POST['edad']) {
$nombre = $mysqli->real_escape_string($_POST['nombre']);
$edad = $mysqli->real_escape_string($_POST['edad']);
$query = "INSERT INTO `empleados` VALUES ('$nombre', $edad)";
echo "Entrada añadida";
$query = "SELECT nombre, edad FROM empleados";
$result = $mysqli->query($query);
echo "<ul>";
foreach($result as $data) {
echo "<li>";
echo $data['nombre'];
echo " - ";
echo $data['edad'];
echo " años";
echo "</li>";
echo "</ul>";
<form method="POST">
<input type="text" name="nombre" placeholder="Inserte el nombre" required/>
<input type="number" name="edad" placeholder="Edad " required/>
<input type="submit" value="Enviar" >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment