-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
51 lines (39 loc) · 1.37 KB
/
create.php
File metadata and controls
51 lines (39 loc) · 1.37 KB
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
<?php
include "./auth.php";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $conn->real_escape_string($_POST['name']);
$price = $conn->real_escape_string($_POST['price']);
$sql = "INSERT INTO products (name, price) VALUES ('$name', '$price')";
if ($conn->query($sql) === TRUE) {
// echo "✅ New record created successfully";
echo "<script>alert('✅ New record created successfully')</script>";
header("Location: ./index.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CREATE</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>CRUD | PHP | Add New Product</h1>
<div class="container">
<a href="./index.php" class="btn btn-add">🏠 Back Home</a>
<form action="" method="post">
<label for="name">Name
<input type="text" name="name" id="name" placeholder="Enter Name here" required>
</label>
<label for="price">Price
<input type="text" name="price" id="price" placeholder="Enter Price here" required>
</label>
<input type="submit" class="btn btn-add" value="Add Product" />
</form>
</div>
</body>
</html>