I have coded a few pages to delete a record from a database but it doesnt seem to work.
I have a website where the user logs in using the correct name and password that is stored in a database, this works fine.
This then takes the user to the admin page, the code consists of some of the following:
<?php
$sql = mysqli_query($con, "SELECT * FROM details INNER JOIN genre ON genre.genreID = details.genreID;") or die(mysqli_error($sql));
while($row = mysqli_fetch_array($sql)) {
echo '<div class="info-box">
<img class="image" src='.'"'.$row['image'].'"
'.'>
<a class="edit" href="delete.php?id=' . $row["ID"] .'" onclick="return confirm(\'Are you sure you want to delete this record?\')">Delete</a> |
</div>';
}
mysqli_close($con);
?>
I have created a JS fiddle with the full code on the admin page ... http://jsfiddle.net/n3n4ot4g/
This page goes to delete.php behind the scenes to delete the record. This page consists of the following code:
<?php
$myID = $_GET['ID'];
echo $myID;
include ('includes/dbconx.php');
//check if a value has been sent
if(isset($myID)){
//MySQL statement to delete record using the unique id variable
mysqli_query($con, "DELETE FROM details WHERE ID = '$myID'") or die ('Error: '.mysqli_error());
}
mysqli_close($con);
header("Location: admin.php");
?>
When i click on the delete link the pop up box appears to confirm the deletion, where i click yes, but then it takes me to admin.php with no content in it. All the records disappear. This also happens when i click on "view records" on the left panel navigation. I can go back and log in again and see the records, but the record i tried to delete will not be deleted.
Im not sure if this is a HTML or PHP problem.
I know JS fiddle is not designed for PHP, but i could not find an alternative.