-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadmin.php
66 lines (63 loc) · 2.02 KB
/
admin.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
<?php require_once("includes/base.php") ?>
<?php require_once("includes/functions.php") ?>
<?php require_once("includes/connection.php") ?>
<?php require_once("backend/ifnotlogin.php") ?>
<?php
$username = $_SESSION['currentuser'];
?>
<?php
if($username!='admin')
{
echo 'You do not have access to this page!!';
}
else if(isset($_POST['submit'])&&$username=='admin')
{
$sub_category_name=$_POST['sub_category_name'];
$category_name=$_POST['category_name'];
//$query1="SELECT MAX(Cat_id) AS Cat_id FROM Category";
//$query_run=mysql_query($query1);
//$catid=mysql_result($query_run,0,'Cat_id');
//$catid=$catid+1;
//$query="INSERT INTO Category (Cat_id,Cat_name) VALUES ('{$cat_id}','{$category_name}')";
$queryii = mysql_query("SELECT * FROM Category WHERE Cat_name = '$category_name'");
if(mysql_num_rows($queryii)==0)
{
$query="INSERT INTO Category (Cat_name) VALUES ('{$category_name}')";
mysql_query($query);
}
$queryii = mysql_query("SELECT * FROM Category WHERE Cat_name = '$category_name'");
if(!$queryii)
{
echo mysql_error();
}
//echo $category_name;
//echo $sub_category_name;
$q1="SELECT * FROM Category Where Cat_name='$category_name'";
$qr = mysql_query($q1);
if(!$qr)
{
echo mysql_error();
}
$Cat_id=mysql_result($qr,0,'Cat_id');
//echo $Cat_id;
//$q="SELECT MAX(Cat_id) FROM Category";
//$qr=mysql_query($q);
//$Sub_id=mysql_result($query_run,0,'Sub_id');
//$Sub_id=$Sub_id+1;*/
$queryii = mysql_query("SELECT * FROM Subcategory WHERE Sub_name = '$sub_category_name'");
if(mysql_num_rows($queryii)==0)
{
$query="INSERT INTO Subcategory (Sub_name,Cat_id) VALUES ('{$sub_category_name}','{$Cat_id}')";
mysql_query($query);
}
}
?>
<html>
<form action="admin.php?user=<?php echo $username;?>" method="post">
<h3>Sub category name:</h3>
<input name="sub_category_name" placeholder="Enter a new sub category" type="text"></input>
<h3>Category name:</h3>
<input name="category_name" placeholder="Enter a new category" type="text"></input>
<button type="submit" name="submit"> Add </button>
</form>
</html>