I have a php file with php code that fetches data from mysql table and displays it in a table. The table contains delete links. To prevent accidental deletion, I added a javascript alert to the delete link. But the javascript does not show the alert dialog box.
below is the picture of the page
From the picture above , the user is expected to be prompted when they click the delete link.
below is my code.
<? php
include('/templates/header.php');
$host = "localhost"; // Host name
$username = "root"; // Mysql username
$password = ""; // Mysql password
$db_name = "datacentre"; // Database name
$tbl_name = "data_centre_users"; // Table name
$server_name = "localhost";
// Create connection
$con = new mysqli($server_name, $username, $password, $db_name, 3306);
if ($con - > connect_error) {
die("Connection failed: ".$con - > connect_error);
}
// Check connection
if ($con - > connect_error) {
die("Connection failed: ".$conn - > connect_error);
}
$sql = "SELECT * FROM $tbl_name WHERE status <> 'approved' ";
$result = $con - > query($sql);
?>
< section id = "sidebar" >
< /section>
<section id="content">
<div id="scroll-table">
<table >
<caption>
List data from mysql
</caption >
< tr >
< th class = "center" > < strong > Name < /strong></th >
< th class = "center" > < strong > Request < /strong></th >
< th class = "center" > < strong > Purpose < /strong></th >
< th class = "center" > < strong > Description < /strong></th >
< th class = "center" > < strong > Approve < /strong></th >
< th class = "center" > < strong > Delete < /strong></th >
< /tr>
<?php
if($result->num_rows > 0){
/ / output data of each row
while ($rows = $result - > fetch_assoc()) { ?>
< tr >
< td class = "center" > <? php echo $rows['first_name']; ?> < /td>
<td class="center"><?php echo $rows['request']; ?></td >
< td class = "center" > <? php echo $rows['purpose']; ?> < /td>
<td class="center"><?php echo $rows['description']; ?></td >
< td class = "center" > < a href = "approve.php?id=<?php echo $rows['id']; ?>"
onclick = "return confirm("
Ae u sure ");" > approve < /a></td >
< td class = "center" > < a href = "delete.php?id=<?php echo $rows['id']; ?>"
onclick = "return confirm('Are you sure you want to delete');" > delete < /a></td >
< /tr>
<?php
}
}
?>
</table >
< /div>
</section >
<?php
$con->close();
include('/templates / footer.php ');
?>