-
Notifications
You must be signed in to change notification settings - Fork 1
/
products.php
134 lines (110 loc) · 3.7 KB
/
products.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
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
<style>
table, th, td {
border: 1px solid black;
/*border-collapse: collapse;*/
}
th, td {
padding: 5px;
}
</style>
<html>
<head>
<meta charset="UTF-8">
<title>Products | FreshProduce</title>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div class="fb-header">
<div id="img1" class="fb-header"><a href="producer.php"><img border="0" alt="FreshProduce" src="icon4.jpeg" width="150" height="150"></a></div>
<form name="loginForm" method="post" action="signout.php">
<div id="form1" class="fb-header">
<!-- <input type="text" placeholder="Email" name="email" id="email" pattern = "[A-Za-z0-9_\-]+@[A-Za-z]+\.[A-Za-z]{2,}" required> -->
</div>
<div id="form2" class="fb-header">
<!-- <input type="password" placeholder="Password" name="pass" id="pass" onkeyup="pwChecker()" required> -->
</div>
<input type="submit" class="submit1" value="Sign out" />
</form>
</div>
<div class='afg'>
<?php
require_once 'dbconnect.php';
$id = $_COOKIE["user_id"];
$query = "SELECT product_id, product_name, cost FROM product WHERE user_id=$id";
$result = mysqli_query($con, $query);
echo "Products<br><br>";
if($result !== false)
{
echo "<table>";
echo "<tr><th>Product ID</th><th>Product Name</th><th>Cost</th></tr>";
while($row = mysqli_fetch_assoc($result)){
echo "<tr>";
foreach($row as $cname => $cvalue){
echo "<td>$cvalue</td>";
}
echo "</tr>";
}
echo "</table><br><br>";
}
?>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(this.readyState==4 && this.status==200) {
var str = this.responseText;
function redirectPost(url, data) {
var form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
}
redirectPost('?', { });
}
};
function addProd() {
var prod_name = document.getElementById("prod_name").value;
var cost = document.getElementById("cost").value;
if(cost=="" || prod_name=="")
{
alert("Enter details");
return false;
}
xmlhttp.open("POST", "add_serv_prod.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var data = "func=add_prod&prod_name="+ prod_name + "&cost=" + cost;
xmlhttp.send(data);
}
function removeProd() {
var prod_id = document.getElementById("prod_id").value;
xmlhttp.open("POST", "add_serv_prod.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var data = "func=rem_prod&prod_id="+prod_id;
xmlhttp.send(data);
}
</script>
<input type="text" name="prod_name" id="prod_name" placeholder="Product" required>
<input type="text" name="cost" id="cost" pattern="[0-9]{1,8}" title="Must be numeric" placeholder="Cost in ₹" required>
<button type="button" onclick="addProd()">Add Product</button>
<br><br>
<br><br>
<input type="text" name="prod_id" id="prod_id" pattern="[0-9]{1,8}" title="Enter numeric ID" placeholder="Product ID to delete" required>
<button type="button" onclick="removeProd()">Remove Product</button>
<br><br>
</div>
</body>
</html>