DELETE FROM not working deletes wrong row
Posted on
16th Feb 2014 07:03 pm by
admin
Hello
I have the following code which i found but it doesnt work properly.. it comes up with a list of the items in the database
e.g.
item 1 - delete
item 2 - delete
item 3 - delete
but when i click delete it deletes a different row and cannot for the life of me figure out why. e.g. if i click delete on item 2 it deletes item 3.
Code: <?php
//If cmd is not hit
if(!isset($cmd))
{
//display all the tbl_testimonies
$result = @mysql_query('SELECT * FROM tbl_testimonies');
if (!$result) {
exit('<p>Error!<br />'.
'Error: ' . mysql_error() . '</p>');
}
while ($r = mysql_fetch_array($result)) {
extract($r);
//grab the tenants_house_name and the tenant_house_id of the enws
$tenants_house_name=$r["tenants_house_name"];//take out the tenants_house_name
$tenant_house_id=$r["tenant_house_id"];//take out the tenant_house_id
echo "<a href='delete.php?cmd=delete&tenant_house_id=$tenant_house_id'>$tenants_house_name - Delete</a>
";
// echo "$tenants_house_name " . "<a href='delete.php?cmd=delete&tenant_house_id=$tenant_house_id'>Delete</a>" ;
}
}
?>
<?php
if($_GET["cmd"]=="delete")
{ $sql = "DELETE FROM tbl_testimonies WHERE tenant_house_id=$tenant_house_id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>
No comments posted yet
Your Answer:
Login to answer
54
29
Other forums
HELP with mysql_real_escape_string
I'm looking to remove apostrophes completely when someone enters lyrics but don't have a clue how to
Multiple forms on the same page (safari)
Hello everyone,
I have 3 forms on the same page, that opens in a new window and submits to a
If statement help please.
Hello on my site I have 2 content boxes. 1 is for the main content (which is the biggest one) and th
Add_Months not Easy to Understand
Oracle is number 1, very fast and very easy. But....
OK, I think but have a problem, only 1 pro
Xml parsing
I need a suggestion about parsing xml with multiply parts like pervious...
i.e. different device
trouble printing an array....
I'm having some trouble printing out an array forwards. I'm figuring out the high and low of an arra
How to use Substr
I want to check for the word CATEGORY: inside a string which can be CATEGORY: ITEM
and remove the
SQL Injection
In my attempts to protect my database from mySQL injection I have created another problem for myself
cURL Upload Help
OK, I am creating a bridge from a local program to my website and I am trying to find the best way t
Logic question
im wondering what's the best method to do the above list:
it is for alliance @ MMORPG game