Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 8, 2019 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/2d40c44ec73712df2aebef4a475268ee to your computer and use it in GitHub Desktop.
Save parzibyte/2d40c44ec73712df2aebef4a475268ee to your computer and use it in GitHub Desktop.
<?php
if (empty($_POST["titulo"])) {
exit("Faltan uno o más datos"); #Terminar el script definitivamente
}
if (empty($_POST["anio"])) {
exit("Faltan uno o más datos"); #Terminar el script definitivamente
}
if (empty($_POST["genero"])) {
exit("Faltan uno o más datos"); #Terminar el script definitivamente
}
#Si llegamos hasta aquí es porque los datos al menos están definidos
include_once __DIR__ . "/base_de_datos.php"; #Al incluir este script, podemos usar $baseDeDatos
# creamos una variable que tendrá la sentencia
$sentencia = $baseDeDatos->prepare("INSERT INTO videojuegos(anio, titulo, genero)
VALUES(:anio, :titulo, :genero);");
# Debemos pasar a bindParam las variables, no podemos pasar el dato directamente
# debido a que la llamada es por referencia
$sentencia->bindParam(":anio", $_POST["anio"]);
$sentencia->bindParam(":titulo", $_POST["titulo"]);
$sentencia->bindParam(":genero", $_POST["genero"]);
$resultado = $sentencia->execute();
if($resultado === true){
echo "Videojuego registrado correctamente";
}else{
echo "Lo siento, ocurrió un error";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment