I am trying to delete an item from my database but it isnt working. I thought I had it working but it was deleting the first item in the database but not the item selected.
Here is what I have.
A link to delete.php then I have this for delete.php
<?php
ob_start();
include_once('../mysql_connect.php');
// contact to database
$host = "localhost";
$username = "admin";
$password = "password";
$database="database";
$tbl_name="new_equip";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$database")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Delete data in mysql from row that has this id
$sql="DELETE FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
// if successfully deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='inventory.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
I know this is probably something simple and I have been searching and trying everything I can find, but I cannot seem to get it working. I believe the delete.php link needs to have the item number in it. Here is what the link is
"delete.php?id=<?php echo $eid; ?>"
I also have this on the top of the delete.php
<?php
$eid = (int) $_GET['id'];
if ($eid < 1)
?>