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 Like 29 Dislike
Previous forums Next forums
Other forums

Undefined offset when using a flat file with pipe symbols
Hi, I've got a flat file/text file which I'm currently using as a member database for my site (not a

how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s

Rss feed question
Hi

My blog and my website are different. Am i able to take my rss feed
from my blog and p

How to kill asynchronous postback / current postback?
Hi,here is my problem:I have a web site with many pages of which some may take time to process resul

Error when call dll from oracle
Hi all, please help me!

I have dll write C language, I want call it from oracle procedur

Forum tutorial
Im a beginner in PHP. Im making a forum(previous questbook, counter and few others) to learn. For no

tag inside php...
hi


Code: <?php
echo "<td width="$columnWidth%" align=&

no idea what to do...
I'm fed up. I had issues with code that I have working on a different site that didn't work on my cu

GMail like Chat in ASP.NET
Hi,Can anyone suggest me, how to incorporate GMail like chat in my existing ASP.Net application.I wa

Loop Through Date Range
Hi guys,
I have date range as parameter like 01/JAN/2009 TO 16/JAN/2009 now i want to loop thro

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash