-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
68 lines (59 loc) · 1.31 KB
/
index.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
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>LAMP App</title>
<link rel="stylesheet" href="styles/styles.css">
</head>
<body>
<h1>LAMP App</h1>
<?php
require_once("login_db.php");
// Add any new users before querying User table
$name = $_POST['name'];
if(isset($name)) {
$query = 'INSERT INTO `sampledb`.`User` (`name`) VALUES ("'.$name.'");';
if ($conn->query($query) === TRUE) {
echo "User created successfully";
} else {
echo "Error: <br>" . $conn->error;
}
}
$query = 'SELECT * FROM User';
$result = $conn->query($query);
if($result) {
echo "<table>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row['user_id']."</td>";
echo "<td>".$row['name']."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "Error: The User table might not have been created yet. Query failed: $query";
}
?>
<h3>Add New User</h3>
<form action="index.php" method="post">
Name: <input type="text" id="name" name="name"><br />
<input type = "submit" onclick="validateUserInfo()">
</form>
<script>
function validateUserInfo() {
var name = document.getElementById("name").value;
if(name === "") {
output += "Name must not be blank.\n";
}
if(output != "") {
alert(output);
}
}
</script>
</body>
</html>
<?php
$conn->close();
?>