-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-create.php
44 lines (39 loc) · 1.06 KB
/
11-create.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
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$conn = require '11-connection.php';
$name = $_POST["name"] ?? NULL;
$email = $_POST["email"] ?? NULL;
if (isset($name) && isset($email)) {
$stmt = $conn->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $email);
$stmt->execute();
header("Location: 11-index.php");
exit;
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CRUD</title>
</head>
<body>
<h1>Add User</h1>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
</div>
<div>
<label for="email">Email:</label>
<input type="email" id="email" name="email">
</div>
<div>
<input type="submit" value="Send">
</div>
</form>
<p><a href="javascript:history.back()"><< Back</a></p>
</body>
</html>