-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-editSubCategories.php
More file actions
76 lines (72 loc) · 2.06 KB
/
Copy pathadmin-editSubCategories.php
File metadata and controls
76 lines (72 loc) · 2.06 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
<?php
require_once "user.php";
CheckIfAdminLoggedIn();
function changeCategory(){
require 'db.php';
try{
$db->beginTransaction();
$db->query('LOCK TABLES subcategory WRITE');
// Add user, then read back and update it with the encrypted one.
$sql = 'UPDATE subcategory set name=:name, visible=:visible where id=:id';
$sth = $db->prepare ($sql);
$sth->bindValue (':name', $_POST['name']);
$sth->bindValue (':visible', $_POST['visible']);
$sth->bindValue (':id', $_POST['id']);
$affected_rows = $sth->execute();
if($affected_rows != 1){
// Should only change for one user at the time
$db->rollBack();
$db->query('UNLOCK TABLES');
throw new Exception('Unable to update information');
}
}catch (Exception $e){
$db->rollBack();
$db->query('UNLOCK TABLES');
throw new Exception('Unable to update information');
}
$db->commit();
header( 'Location: admin-editCategories.php' );
echo "<p>Update done";
}
?>
<?php
include 'Geeksforsaletop.php';
?>
<div id="content">
<?php
include 'admin-buttons.php';
?>
<t1> Edit a subcategory</t1></br>
<?php
if(isset($_POST['name'])){
try{
changeCategory();
}catch(Exception $e){
echo $e->getMessage();
}
}
if(isset($_POST['category'])){
// Get ID of top category
$sql = 'select * from subcategory where id = :id';
$sth = $db->prepare($sql);
$sth->bindValue (':id', $_POST['category']);
$sth->execute();
$sth->setFetchMode(PDO::FETCH_ASSOC);
// only add if we only found one category
if($sth->rowCount() === 1){
$row = $sth->fetch();
}
}
?>
<form method="post" action="admin-editSubCategories.php">
<input type="hidden" name="id" value="<?php echo $row['id'];?>"/>
<label for="name">Name</label>
<input type="text" name="name" required value ="<?php echo $row['name'];?>"/></br>
<label for="visible">Visible?</label>
<select id="visible" name="visible" required>
<option value="1">Visible</option>
<option value="0">Not visible</option>
</select></br></br>
<input type="submit" value="Update"/>
</div>
</BODY>