-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_region.php
117 lines (74 loc) · 1.76 KB
/
new_region.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
113
114
115
116
117
<?php
session_start();
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>New Region</title>
<style>
table,th, tr,td {border: #000 1px solid;}
</style>
</head>
<?php
require('header.php');
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['username1']))
{
?>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$region = htmlspecialchars($_POST["region"]);
$regex = "/^[a-zA-Z.]{3,255}$/";
if (preg_match($regex, $region) === 1) {
echo '<div class="error">Region must be between 3 and 255</div>';
}else{
$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);
$sql = "INSERT INTO Region (RegionName) VALUES ('$region')";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
//echo $result;
if ($result == 1) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
mysql_close($con);
}
}
?>
<form action="new_region.php" method="post">
New Region: <input type="text" name="region" size="50">
<br><br>
<input type="submit">
</form>
<?php
// TABLE WITH LISTING
echo "<br>";
echo "<br>";
echo "<br>";
$con = mysql_connect($servername,$username,$password) or die('Could not connect:'.mysql_error());
mysql_select_db($database, $con) or die('Could not select database.');
$result = mysql_query("SELECT * FROM Region");
echo '<table class="table">';
echo "<tr>";
echo "<th>Locations</th>";
echo "</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>". $row[0] . "</td>";
echo "</tr>";
}
echo '</table>';
mysql_close($con);
?>
</body>
<?php
}
else{
echo "Please, login to see this page.";
echo "<br>";
}
require('footer.php');
?>
</html>