Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 14, 2019 21:18
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/413e754b9ba856c8b9fd1f9fe014886e to your computer and use it in GitHub Desktop.
Save parzibyte/413e754b9ba856c8b9fd1f9fe014886e to your computer and use it in GitHub Desktop.
<?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