-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathdelete.php
More file actions
80 lines (59 loc) · 2.21 KB
/
delete.php
File metadata and controls
80 lines (59 loc) · 2.21 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
<?php require "templates/header.php"; ?>
<div class="center-align">
<?php
if (isset($_POST['submit'])) {
require "database/config.php";
//Establish the connection
$conn = mysqli_init();
mysqli_ssl_set($conn,NULL,NULL,$sslcert,NULL,NULL);
if(!mysqli_real_connect($conn, $host, $username, $password, $db_name, 3306, MYSQLI_CLIENT_SSL)){
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
//Test if table exists
$res = mysqli_query($conn, "SHOW TABLES LIKE 'Products'");
if (mysqli_num_rows($res) <= 0) {
echo "<h2>Catalog is empty</h2>";
} else {
//Delete data
$ProductName = $_POST['ProductName'];
if ($stmt = mysqli_prepare($conn, "DELETE FROM Products WHERE ProductName = ?")) {
mysqli_stmt_bind_param($stmt, 's', $ProductName);
mysqli_stmt_execute($stmt);
if (mysqli_stmt_affected_rows($stmt) == 0) {
echo "<h2>Product \"$ProductName\" was not found in the catalog.</h2>";
}
else {
echo "<h2>Product \"$ProductName\" has been removed from the catalog.</h2>";
}
mysqli_stmt_close($stmt);
}
}
//Close the connection
mysqli_close($conn);
} else {
?>
<h2>Remove a Product</h2>
<br>
<form method="post" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<table>
<tr>
<td class="no-border"> <label for="ProductName">Product Name</label> </td>
<td class="no-border"> <input type="text" name="ProductName" id="ProductName"> </td>
</tr>
</table>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
?>
<br> <br> <br>
<table>
<tr>
<td> <a href="delete.php">Remove Another Product</a> </td>
<td> <a href="read.php">View Catalog</a> </td>
<td> <a href="index.php">Back to Home Page</a> </td>
</tr>
</table>
</div>
<?php require "templates/footer.php"; ?>