Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 8, 2019 01:09
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/14dce96c4e71fe2fcd0576055a4cedd0 to your computer and use it in GitHub Desktop.
Save parzibyte/14dce96c4e71fe2fcd0576055a4cedd0 to your computer and use it in GitHub Desktop.
<?php
if (empty($_POST["id"])) { # En este caso también necesitamos al ID
exit("Faltan uno o más datos"); #Terminar el script definitivamente
}
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("UPDATE videojuegos
SET anio = :anio,
titulo = :titulo,
genero = :genero
WHERE id = :id");
#Pasar los datos...
$sentencia->bindParam(":id", $_POST["id"]);#Aquí pasamos el ID
$sentencia->bindParam(":anio", $_POST["anio"]);
$sentencia->bindParam(":titulo", $_POST["titulo"]);
$sentencia->bindParam(":genero", $_POST["genero"]);
$resultado = $sentencia->execute();
if($resultado === true){
echo "Videojuego guardado correctamente";
echo '<br><a href="3_tabla_dinamica.php">Ver los videojuegos</a>';
}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