-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddItem.php
56 lines (52 loc) · 1.41 KB
/
addItem.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
<?php $dir = ""; include($dir . "header.php"); ?>
<link rel = "stylesheet" href ="css/table.css">
<?php
if(isset($_POST['sub'])){
$servername = "localhost";
$username = "root";
$password = "admin";
$dbname = "cscomp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * from items WHERE name = '".$_POST['name']."';";
// echo $sql;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "already taken";
} else {
$name = $_POST['name'];
$price = $_POST['price'];
$sql = "INSERT INTO items(name, price, available) VALUES('".$name."','".$price."','yes')";
// echo $sql;
$result = $conn->query($sql);
}
// if($result->num_row==0){
// // $sql = "INSERT items SET available='yes' WHERE item_id=".$_GET['toggleYes'].";";
// // // echo $sql;
// // $result = $conn->query($sql);
// echo "lmao available";
// }
$conn->close();
}
?>
<form action="addItem" method="post">
<table id='menu'>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
<tr>
<th>
<input type="text" name="name" value="">
</th>
<th>
<input type="number" name="price" value="">
</th>
</tr>
</table>
<center><input type="submit" name="sub" value="Add"></center>
</form>