-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path18.html_form.php
79 lines (66 loc) · 2.05 KB
/
18.html_form.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
<?php
include "db_secure.php";
if (!($connection = @ mysql_connect(DB_HOST, 'conference', 'conference'))) {
showerror();
}
if (!mysql_select_db('conference', $connection)) {
showerror();
}
if (!isset($_GET['registrant'])) {
$query = "SELECT * FROM registrations2 ORDER BY name";
// echo $query;
if (!$result = mysql_query($query)) {
showerror();
}
$registrants = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$registrants[$row['id']] = $row;
}
} else if ($_GET['registrant'] == 'Submit') {
$id = mysqlclean($_GET, "registrant_id", 11, $connection);
if (!isset($id)) {
die('no id given');
}
$query = "SELECT * FROM registrations2 WHERE id = {$id}";
// echo $query;
if (!$result = mysql_query($query)) {
showerror();
}
if (mysql_num_rows($result) == 1) {
$edit_registrant = mysql_fetch_array($result, MYSQL_ASSOC);
} else {
// something bad has happened
exit;
}
}
?>
<html>
<head>
<title>Update Registration form</title>
</head>
<body>
<?php if (!isset($_GET['registrant'])): ?>
<form action="18.html_form.php" method="GET">
Registrant:<select name="registrant_id">
<?php foreach ($registrants as $id => $registrant): ?>
<option value="<?php echo $id; ?>"><?php echo $registrant['name']; ?></option>
<?php endforeach; ?>
</select><br>
<input type="submit" name ="registrant" value="Submit">
</form>
<?php endif; ?>
<?php if (isset($edit_registrant) && !empty($edit_registrant)): ?>
<form action="18.write_query.php" method="POST">
Name: <input type="text" name="name" value="<?php echo $edit_registrant['name']; ?>"><br>
Email: <input type="text" name="email" value="<?php echo $edit_registrant['email']; ?>"><br>
Category:<select name="category">
<option value="1">Staff
<option value="2">Student
<option value="3">Other
</select><br>
<input type="hidden" name="id" value="<?php echo $edit_registrant['id']; ?>">
<input type="submit">
</form>
<?php endif; ?>
</body>
</html>