FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
T2-Web-Programming/upload_category.php at main · MilkyWay2k/T2-Web-Programming · GitHub
MilkyWay2k
/
T2-Web-Programming
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
T2-Web-Programming
/
upload_category.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
124 lines (95 loc) · 4.34 KB
Breadcrumbs
T2-Web-Programming
/
upload_category.php
Copy path
File metadata and controls
124 lines (95 loc) · 4.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<?php
$
title
=
"
Skate Shop - Shop Page
"
;
$
stylesheet
=
"
shop
"
;
$
extra
=
"
<link rel=
\"
stylesheet
\"
href=
\"
https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css
\"
>
"
;
include
"
partials/header.php
"
;
include
"
partials/db.php
"
;
?>
<script src="js/val1.js"></script>
<div class="container">
<a href="upload_products.php" class="btn border mb-4 mt-4">@upload product@</a><br>
<a href="profile.php" class="btn border mb-4"> <= back to the dashboard bro*</a>
<h1>Create Category</h1>
<form action="upload_category.php" method="post" enctype="multipart/form-data" name="cat">
<label for="category_name">Category Name:</label>
<input type="text" name="category_name" id="category_name">
<br>
<label>Category Image:</label>
<input type="file" name="category_image"><br><br>
<input type="hidden" name="submitted" value="true">
<input type="submit" name="submit" value="Add Category" onclick="return valCat()">
</form>
<?php
if
(
isset
(
$
_POST
[
'
submit
'
])) {
$
category_name
=
$
_POST
[
'
category_name
'
];
// Check if a file was uploaded
if
(!
empty
(
$
_FILES
[
'
category_image
'
][
'
tmp_name
'
]) &&
is_uploaded_file
(
$
_FILES
[
'
category_image
'
][
'
tmp_name
'
])) {
// Read the file contents and escape special characters
$
category_image
=
addslashes
(
file_get_contents
(
$
_FILES
[
'
category_image
'
][
'
tmp_name
'
]));
// Prepare the SQL statement to insert the new category
$
sql
=
"
INSERT INTO product_category (category_name, category_image) VALUES ('
$
category_name
', '
$
category_image
')
"
;
// Execute the SQL statement and check for errors
if
(
$
conn
->
query
(
$
sql
) ===
TRUE
) {
echo
"
New category added successfully!
"
;
}
else
{
echo
"
Error:
"
.
$
sql
.
"
<br>
"
.
$
conn
->
error
;
}
}
else
{
// No file was uploaded
echo
"
Error: No category image was uploaded.
"
;
}
}
?>
<?php
$
sql
=
"
SELECT * FROM product_category
"
;
$
result
=
$
conn
->
query
(
$
sql
);
// Check if there are any categories
if
(
$
result
->
num_rows
>
0
) {
// Output data of each category
while
(
$
row
=
$
result
->
fetch_assoc
()) {
echo
"
Category ID:
"
.
$
row
[
"
category_id
"
] .
"
<br>
"
;
echo
"
Category Name:
"
.
$
row
[
"
category_name
"
] .
"
<br>
"
;
echo
'
<img src="data:image/jpeg;base64,
'
.
base64_encode
(
$
row
[
'
category_image
'
] ).
'
"/>
'
;
//update category ID and name
echo
"
<form action='upload_category.php' method='POST' name='update'>
<input type='hidden' name='category_id' value='
"
.
$
row
[
'
category_id
'
] .
"
'>
<label for='new_category_id'>New Category ID:</label>
<input type='text' id='new_category_id' name='new_category_id' value='
"
.
$
row
[
'
category_id
'
] .
"
'><br>
<label for='new_category_name'>New Category Name:</label>
<input type='text' name='new_category_name' value='
"
.
$
row
[
'
category_name
'
] .
"
'><br>
<input type='submit' name='update' value='Update' onclick='return valUp()'>
</form>
"
;
//delete category
echo
"
<form action='upload_category.php' method='POST'>
<input type='hidden' name='category_id' value='
"
.
$
row
[
'
category_id
'
] .
"
'>
<input type='submit' name='delete' value='Delete'>
</form>
"
;
echo
"
<hr>
"
;
}
}
else
{
echo
"
No categories found.
"
;
}
if
(
isset
(
$
_POST
[
'
update
'
])) {
$
category_id
=
$
_POST
[
'
category_id
'
];
$
new_category_name
=
$
_POST
[
'
new_category_name
'
];
$
new_category_id
=
$
_POST
[
'
new_category_id
'
];
$
query_update
=
"
UPDATE product_category SET category_id='
$
new_category_id
', category_name='
$
new_category_name
' WHERE category_id =
$
category_id
"
;
mysqli_query
(
$
conn
,
$
query_update
);
echo
"
<meta http-equiv='refresh' content='0'>
"
;
exit
;
}
if
(
isset
(
$
_POST
[
'
delete
'
])) {
$
category_id
=
$
_POST
[
'
category_id
'
];
$
query_delete
=
"
DELETE FROM product_category WHERE category_id =
$
category_id
"
;
mysqli_query
(
$
conn
,
$
query_delete
);
header
(
"
Location: upload_category.php
"
);
echo
"
<meta http-equiv='refresh' content='0'>
"
;
exit
;
}
?>
</div>
<?php
include
'
partials/footer.php
'
;
?>
Back
|
FazBrowse Home
|
New Git URL