-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddgroceryprocess.php
103 lines (87 loc) · 3.38 KB
/
addgroceryprocess.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
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap4.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
</head>
</html>
<?php
include_once("connection.php");
require_once("addgrocery.php");
$err_msg="";
$pro = trim($_POST["pro"]);
$search = "SELECT ProductName FROM products WHERE ProductName = '$pro'";
$aaa = $conn->query($search);
if ($aaa->num_rows != 0){
$id = $aaa->fetch_array()['ProductName'];
$err_msg .="<div class=container>
<div class=row style=padding-top:1%;>
<div class=col-md-12>
<div class=form-row>
<div class=form-group col-md-4>Product name already exists.</div></div></div></div></div>";
}
/*
if($pro=="")
$err_msg .= "<p>Please enter Product Name.</p>";
else if(!preg_match("/^[a-zA-Z0-9 ]+$/",$pro))
$err_msg .= "<p>Do not enter special characters.</p>";
else if (strlen($pro) > 30)
$err_msg .= "<p>Product Name too long.</p>";
*/
$cat = trim($_POST["cat"]);/*
if($cat=="")
$err_msg .= "<p>Please enter Category</p>";
else if(strlen($cat) > 15)
$err_msg .= "<p>Category too long</p>";
*/
$pri = trim($_POST["pri"]);/*
if($pri=="")
$err_msg .= "<p>Please enter Price.</p>";
else if($pri > 299)
$err_msg .= "<p>Too expensive</p>";
*/
$amo = trim($_POST["amo"]);/*
if($amo=="")
$err_msg .= "<p>Please enter amount.</p>";
else if(!preg_match("/^[0-9]+$/",$amo))
$err_msg .= "<p>Please enter numbers.</p>";
*/
if ($err_msg!=""){
echo $err_msg;
exit();
}
$status = "New";
$result = mysqli_query($conn, $query);
if ($result){
$insert_query = "INSERT INTO products (
ProductName,
Category,
Price,
Stock)
VALUES ('$pro','$cat','$pri','$amo')";
$insert_result = mysqli_query($conn, $insert_query);
if ($insert_result)
echo "<div class=container>
<div class=row style=padding-top:1%;>
<div class=col-md-12>
<div class=form-row>
<div class=form-group col-md-4>
<p>Add grocery successful, if you want to view the table please press Products at the top.</p></div></div></div></div></div>";
else
echo "<div class=container>
<div class=row style=padding-top:1%;>
<div class=col-md-12>
<div class=form-row>
<div class=form-group col-md-4><p>Add not successful.</p></p></div></div></div></div></div>";
}
else {
echo "<div class=container>
<div class=row style=padding-top:1%;>
<div class=col-md-12>
<div class=form-row>
<div class=form-group col-md-4><p>Create table unsuccessful.</p></p></div></div></div></div></div>";
}
?>