Created
October 14, 2019 21:36
-
-
Save parzibyte/6a8b98ac7079901b5e24b7ef108b2ce0 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 (!isset($_GET["id"])) { | |
exit(); | |
} | |
$id = $_GET["id"]; | |
include_once "database.php"; | |
$statement = $database->prepare("SELECT * FROM person WHERE id = ?;"); | |
$statement->execute([$id]); | |
$person = $statement->fetch(PDO::FETCH_OBJ); | |
if ($person === false) { | |
#not found | |
echo "Person not found!"; | |
exit(); | |
} | |
#If the person exists, this code is executed | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Edit person</title> | |
</head> | |
<body> | |
<form method="post" action="update.php"> | |
<!-- Put the id hidden in the form so we can use it later --> | |
<input type="hidden" name="id" value="<?php echo $person->id; ?>"> | |
<label for="nombre">Name:</label> | |
<br> | |
<input value="<?php echo $person->first_name ?>" name="first_name" required type="text" id="first_name" placeholder="First name"> | |
<br><br> | |
<label for="last_name">Last name:</label> | |
<br> | |
<input value="<?php echo $person->last_name ?>" name="last_name" required type="text" id="last_name" placeholder="Last name"> | |
<br><br> | |
<label for="gender">Gender</label> | |
<select name="gender" required name="gender" id="gender"> | |
<!-- | |
Para seleccionar una opción con defecto, se debe poner el atributo selected. | |
Usamos el operador ternario para que, si es esa opción, marquemos la opción seleccionada | |
--> | |
<option value="">--Please select--</option> | |
<option <?php echo $person->gender === 'M' ? "selected='selected'" : "" ?> value="M">Male</option> | |
<option <?php echo $person->gender === 'F' ? "selected='selected'" : "" ?> value="F">Female</option> | |
</select> | |
<br><br><input type="submit" value="Save"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment