Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 14, 2019 21:42
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/5d3df5a6c943ce08080e4ea1da5529f9 to your computer and use it in GitHub Desktop.
Save parzibyte/5d3df5a6c943ce08080e4ea1da5529f9 to your computer and use it in GitHub Desktop.
<?php
#If one of these are not present, exit
if (
!isset($_POST["first_name"]) ||
!isset($_POST["last_name"]) ||
!isset($_POST["gender"]) ||
!isset($_POST["id"])
) {
exit();
}
#If everything is OK, this code is executed
include_once "database.php";
$id = $_POST["id"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$gender = $_POST["gender"];
$statement = $database->prepare("UPDATE person SET first_name = ?, last_name = ?, gender = ? WHERE id = ?;");
$result = $statement->execute([$first_name, $last_name, $gender, $id]); # Pass data in the same order as placeholders
if ($result === true) {
echo "Saved";
} else {
echo "Something went wrong";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment