Created
August 8, 2019 00:13
-
-
Save parzibyte/2d40c44ec73712df2aebef4a475268ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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