Created
October 14, 2019 21:18
-
-
Save parzibyte/413e754b9ba856c8b9fd1f9fe014886e 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 one of these fields are not present, exit | |
if (!isset($_POST["first_name"]) || !isset($_POST["last_name"]) || !isset($_POST["gender"])) { | |
exit(); | |
} | |
# If everything is OK this code is executed | |
include_once "database.php"; | |
$first_name = $_POST["first_name"]; | |
$last_name = $_POST["last_name"]; | |
$gender = $_POST["gender"]; | |
/* | |
When we include the "database.php" file, all of its variables are present | |
in the current scope, so we can access "$database" defined in the file | |
*/ | |
$statement = $database->prepare("INSERT INTO person(first_name, last_name, gender) VALUES (?, ?, ?);"); | |
$result = $statement->execute([$first_name, $last_name, $gender]); # Pasar en el mismo orden de los ? | |
#execute returns true or false depending on success | |
if ($result === true) { | |
echo "Inserted successfully"; | |
} else { | |
echo "Something went wrong"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment