-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddproduct.php
More file actions
142 lines (95 loc) · 3.12 KB
/
addproduct.php
File metadata and controls
142 lines (95 loc) · 3.12 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
echo <<<TAG
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<script type="text/javascript" src="js/scripts.js"></script>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
TAG;
if (isset($_POST['code'])) {
$code = $_POST['code'];
$type = $_POST['type'];
$price = $_POST['price'];
$stock = $_POST['stock'];
$servername = "127.0.0.1";
$DBusername = "root";
$password = "";
$dbname = "smarthouse";
$conn = new mysqli($servername, $DBusername, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO product_stock(product_code, type_code, price ,stock)
VALUES ('" . $code . "', '" . $type . "', '" . $price . "','" . $stock . "')";
echo <<<TAG
<body>
<div class="form">
TAG;
if ($conn->query($sql) === TRUE) {
echo "<h1>محصول اضافه شد</h1>";
} else {
// if (strpos($conn->error, 'PRIMARY') !== true)
// echo "<h1>خطا: " . "<br>" . "کد محصول وارد شده تکراری است" . "</h1>";
// else
echo "<h1>Error: " . "<br>" . $conn->error . "</h1>";
}
echo "<a href=\"#\" onclick=\"back()\" class=\"btn btn-red\">بازگشت</a>";
echo <<<TAG
</div> <!-- /form -->
</body>
TAG;
} else {
echo <<<TAG
<body>
<div class="form">
<div id="signup">
<h1>اضافه کردن محصول</h1>
<form action="./addproduct.php" method="post">
<div class="field-wrap">
<input type="text" name="code" required placeholder="کد محصول">
</div>
<div class="field-wrap">
<select name="type">
TAG;
$servername = "127.0.0.1";
$DBusername = "root";
$password = "";
$dbname = "smarthouse";
$conn = new mysqli($servername, $DBusername, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "select * from product_type;";
$result = $conn->query($query);
while($row = $result->fetch_assoc()) {
if ($result->num_rows > 0) {
echo " <option value=\"".$row['type_code']."\">".$row['type']."</option>";
}
}
echo <<<TAG
</select>
</div>
<div class="field-wrap">
<input type="text" name="price" required placeholder="قیمت">
</div>
<div class="field-wrap">
<input type="text" name="stock" required placeholder="موجودی">
</div>
<button type="submit" class="button button-block"/>اضافه کن!</button>
</form>
</div>
</div> <!-- /form -->
</body>
TAG;
}
echo <<<TAG
</html>
TAG;