-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_product.php
106 lines (93 loc) · 2.23 KB
/
add_product.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ajouter Produit</title>
</head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}
h1 {
text-align: center;
margin-top: 50px;
}
form {
max-width: 600px;
margin: 0 auto;
background-color: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
input[type=text],
input[type=number] {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
}
input[type=submit] {
display: block;
margin: 30px auto 0;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #0062cc;
}
</style>
<body>
<h1>Add Product</h1>
<form method="post">
<div class="form-group">
<label for="name">Nom du produit:</label>
<input type="text" name="name" id="name">
</div>
<div class="form-group">
<label for="price">Prix:</label>
<input type="number" name="price" id="price">
</div>
<div class="form-group">
<label for="image">Image URL:</label>
<input type="text" name="image" id="image">
</div>
<input type="submit" value="Add Product">
</form>
</body>
</html>
<?php
$products_file = "products.txt";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form data
$name = $_POST["name"];
$price = $_POST["price"];
$image = $_POST["image"];
if (!empty($name) && !empty($price) && !empty($image)) {
// Open the products file
$file = fopen($products_file, "a");
if ($file) {
fwrite($file, "$name|$price|$image\n");
fclose($file);
header("Location: main.php");
exit();
} else {
echo "Error: Could not open file.";
}
}
}