-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path20.write_query.php
63 lines (53 loc) · 1.35 KB
/
20.write_query.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
<?php
include "db_secure.php";
if (!($connection = @ mysql_connect(DB_HOST, 'conference', 'conference'))) {
showerror();
}
$name = mysqlclean($_POST, "name", 50, $connection);
$email = mysqlclean($_POST, "email", 50, $connection);
$category = mysqlclean($_POST, "category", 50, $connection);
if (!mysql_select_db('conference', $connection)) {
showerror();
}
// lock tables
$lock_query = "LOCK TABLES registrations3 WRITE";
if (!mysql_query($lock_query)) {
showerror();
}
$id_query = "SELECT MAX(id) AS id FROM registrations3";
if (!$result = mysql_query($id_query)) {
showerror();
}
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$next_id = $row['id'] + 1;
} else if (mysql_num_rows($results) == 0) {
$next_id = 1;
} else {
// something bad has happened
exit;
}
$query = "INSERT INTO registrations3 VALUES ({$next_id}, '{$name}', '{$email}', {$category})";
// echo $query;
if (!mysql_query($query)) {
showerror();
}
// unlock tables
$unlock_query = "UNLOCK TABLES";
if (!mysql_query($unlock_query)) {
showerror();
}
?>
<html>
<head>
<title>Registration feedback</title>
</head>
<body>
<?php
echo "The data you entered was:<br>";
echo "Name: {$name}<br>";
echo "Email: {$email}<br>";
echo "Category: {$category}<br>";
?>
</body>
</html>