-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.php!
61 lines (50 loc) · 1.4 KB
/
home.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
<?php
require_once 'library.php';
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) mysqli_ferror($conn);
$query = "SELECT * FROM people";
$result = $conn->query($query);
if (!$result) msqli_ferror($conn);
$num_users = $result->num_rows;
if ($conn->connect_error) mysqli_ferror($conn);
$msg = "";
if (!empty($_POST['name']) &&
!empty($_POST['age']) &&
!empty($_POST['restrictions']) )
{
$name = get_post($conn, 'name');
$age = get_post($conn, 'age');
$restrictions = get_post($conn, 'restrictions');
$query = "INSERT INTO people(name, age, restrictions) VALUES" .
"('$name', '$age', '$restrictions')";
$result = $conn->query($query);
if (!$result) {
$msg = "Query failed: $query <br> $conn->error <br>";
} else {
$msg = "Welcome, $name!";
}
}
// by convention, files include their outermost tags
echo "<html>";
echo file_get_contents("header.html");
echo "<body>";
echo file_get_contents("head.html");
echo file_get_contents("nav.html");
echo <<<_END
<main>
<h2>New Member Signup</h2>
<form action="signup.php" method="post">
<ul>
<li>Name: <input type="text" name="name"></li>
<li>Age: <input type="text" name="age"></li>
<li>Dietary Restrictions: <input type="text" name="restrictions" value="None"></li>
</ul>
<p>$msg</p>
<input type="submit" value="Sign up">
</form>
</main>
_END;
echo file_get_contents("footer.html");
echo "</html>"
?>