Repository navigation
Expand file tree
/
Copy pathUpdate_Category.php
More file actions
89 lines (86 loc) · 3.08 KB
/
Copy pathUpdate_Category.php
File metadata and controls
89 lines (86 loc) · 3.08 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
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="utf-8" />
<link rel="stylesheet" href="css/bootstrap.min.css">
<?php
include_once("connection.php");
if(isset($_GET["id"]))
{
$id= $_GET["id"];
$result = mysqli_query($conn,"SELECT * FROM category where cat_id='$id'");
$row = db_fetch_assoc($result);
$cat_id = $row['cat_id'];
$cat_name = $row['cat_name'];
$cat_des = $row['cat_des'];
?>
<div class="container">
<h2>Updating Product Category</h2>
<form id="form1" name="form1" method="post" action="" class="form-horizontal" role="form">
<div class="form-group">
<label for="txtTen" class="col-sm-2 control-label">Category ID(*): </label>
<div class="col-sm-10">
<input type="text" name="txtID" id="txtID" class="form-control" placeholder="Catepgy ID" readonly
value='<?php echo $cat_id ;?>'>
</div>
</div>
<div class="form-group">
<label for="txtTen" class="col-sm-2 control-label">Category Name(*): </label>
<div class="col-sm-10">
<input type="text" name="txtName" id="txtName" class="form-control" placeholder="Catepgy Name"
value='<?php echo $cat_name;?>'>
</div>
</div>
<div class="form-group">
<label for="txtMoTa" class="col-sm-2 control-label">Description(*): </label>
<div class="col-sm-10">
<input type="text" name="txtDes" id="txtDes" class="form-control" placeholder="Description"
value='<?php echo $cat_des;?>'>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" name="btnUpdate" id="btnUpdate" value="Update" />
<input type="button" class="btn btn-primary" name="btnIgnore" id="btnIgnore" value="Ignore"
onclick="window.location='Category_Management.php'" />
</div>
</div>
</form>
</div>
<?php
}
else
{
echo '<meta http-equiv="Refresh" content="0; URL=?page=category_management"/>';
}
?>
<?php
if(isset($_POST["btnUpdate"]))
{
$id= $_POST["txtID"];
$name= $_POST["txtName"];
$des = $_POST["txtDes"];
$err="";
if($name=="")
{
$err .= "<li>Enter Category Name, please</li>";
}
if($err!="")
{
echo "<ul>$err</ul>";
}
else
{
$sq = "SELECT * FROM category WHERE cat_id != '$id' and cat_name='$name'";
$result= mysqli_query($conn, $sq);
if(mysqli_num_rows($result)==0)
{
mysqli_query($conn, "UPDATE category SET cat_name ='$name', cat_des='$des' where cat_id='$id'");
echo '<meta http-equiv="Refresh" content="0; URL=?page=category_management"/>';
}
else
{
echo "<li>Duplicate category Name</li>";
}
}
}
?>