-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_children.php
112 lines (101 loc) · 3.47 KB
/
update_children.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
*@Author Rayyan Hussain
*/
require_once 'config.inc.php';
// Get Customer Number
$id = $_GET['id'];
if ($id === "") {
header('location: list_children.php');
exit();
}
if ($id === false) {
header('location: list_children.php');
exit();
}
if ($id === null) {
header('location: list_children.php');
exit();
}
?>
<html>
<head>
<title>Missing Child DB</title>
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<?php
require_once 'header.inc.php';
?>
<div class = "container">
<br>
<h2>Update Child Age</h2>
<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $database, $port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check the Request is an Update from User -- Submitted via Form
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$age = $_POST['age'];
if ($age === null)
echo "<div><i>Specify a new age</i></div>";
else if ($age === false)
echo "<div><i>Specify a new age</i></div>";
else if (trim($age) === "")
echo "<div><i>Specify a new age</i></div>";
else {
/* perform update using safe parameterized sql */
$sql = "UPDATE Person SET age = ? WHERE personID = ?";
$stmt = $conn->stmt_init();
if (!$stmt->prepare($sql)) {
echo "failed to prepare";
} else {
// Bind user input to statement
$stmt->bind_param('ss', $age,$id);
// Execute statement and commit transaction
$stmt->execute();
$conn->commit();
}
}
}
/* Refresh the Data */
$sql = "SELECT personID,firstName,middleName,lastName,birthDate,age FROM Person WHERE personID = ?";
$stmt = $conn->stmt_init();
if (!$stmt->prepare($sql)) {
echo "failed to prepare";
}
else {
$stmt->bind_param('s',$id);
$stmt->execute();
$stmt->bind_result($personID,$firstName,$middleName,$lastName,$birthDate,$age);
?>
<form method="post">
<input type="hidden" name="id" value="<?= $id ?>">
<?php
while ($stmt->fetch()) {
echo '<a href="show_children.php?id='. $firstName . '"></a>' . '<p><strong>Name: </strong>'. $firstName .' '.$middleName .' '. $lastName . '</p>' . "<p><strong>Birth Date: </strong>$birthDate <br><strong>Age: </strong>$age </p>";
}
?>
<!-- <input type="text" name="age" class="form-control col-md-6" placeholder="Input New Age">
<button class = "btn col-auto" type="submit number">Update</button> -->
<div class="input-group mb-3">
<input type="text" name ="age" class="form-control" placeholder="Input New Age">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit number">Update</button>
</div>
</div>
<br>
<br>
<button type="button" class="btn btn-dark"><a class="text-white" href="show_children.php?id=<?= $personID ?>">Back to details</a></button>
</form>
<?php
}
$conn->close();
?>
</>
</body>
</html>