-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditem.php
More file actions
128 lines (109 loc) · 4.2 KB
/
additem.php
File metadata and controls
128 lines (109 loc) · 4.2 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
<?php include "inc/header.php";?>
<?php include_once "lib/Database.php";?>
<?php include "inc/sidenav.php";?>
<style>
#additem {
width: 700px;
max-width: 100%;
margin: 0 auto;
border: 1px solid #d8d8d8;
padding: 30px 40px;
}
#additem label {
font-size: 1.8rem;
line-height: 1.8;
}
#itemDescription,
input {
width: 100%;
padding: 5px;
line-height: 1.8;
font-size: 1.8rem;
border-radius: 8px;
border-color: #d1d1d1;
margin: 5px 0;
}
#itemStatus {
font-size: 1.8rem;
padding: 5px;
margin-left: 30px;
}
#additem input[type="submit"] {
margin-top: 30px;
cursor: pointer; /* Add cursor pointer for submit button */
}
.message {
margin-top: 20px;
font-size: 1.6rem;
}
</style>
<section>
<div class="container">
<h1>Add New Item</h1>
<form id="additem" enctype="multipart/form-data">
<label class="" for="itemName">Item Name:</label><br>
<input class="" type="text" id="itemName" name="itemName"><br>
<label for="itemCategory">Item Category:</label>
<select id="proCategoriesId" class="form-select form-select-lg mb-3" aria-label=".form-select-lg example" name="cateId">
<option>Select Category</option>
<?php
$query = "SELECT * FROM tbl_category";
$category = $db->select($query);
if ($category) {
while ($result = $category->fetch_assoc()) {?>
<option value="<?php echo $result['cateId']; ?>"><?php echo $result['cateName']; ?></option>
<?php }} ?>
</select><br>
<label for="itemType">Item Type:</label>
<select id="proCategoriesId" class="form-select form-select-lg mb-3" aria-label=".form-select-lg example" name="typeId">
<option>Select Type</option>
<?php
$query = "SELECT * FROM tbl_type";
$category = $db->select($query);
if ($category) {
while ($result = $category->fetch_assoc()) {?>
<option value="<?php echo $result['typeId']; ?>"><?php echo $result['typeName']; ?></option>
<?php }} ?>
</select><br>
<label for="itemDescription">Item Description:</label><br>
<textarea id="itemDescription" name="itemDescription" rows="4" cols="50"></textarea><br>
<label for="itemPrice">Item Price:</label><br>
<input type="text" id="itemPrice" name="itemPrice"><br>
<label for="itemStatus">Item Status:</label>
<select id="itemStatus" name="itemStatus">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select><br>
<label for="itemImg">Item Image:</label><br>
<input type="file" id="itemImg" name="itemImg"><br>
<label for="itemSlug">Item Slug:</label><br>
<input type="text" id="itemSlug" name="itemSlug"><br>
<input type="submit" class="submit" value="Submit">
<div id="message"></div>
</form>
</div>
</section>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#additem').submit(function(e){
e.preventDefault(); // Prevent the form from submitting normally
let formData = new FormData(this);
$.ajax({
type: "POST",
url: "additem_handler.php",
data: formData,
contentType: false,
processData: false,
success: function(response){
$('#message').html(response);
$('#additem')[0].reset(); // Clear the form fields after successful submission
},
error: function(){
$('#message').html("There was an error adding the item to the cart.");
}
});
});
});
</script>
<?php include "inc/footer.php"; ?>