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.
Did you know?Explore Trending and Topic pages for more stories like this.
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

How to schedule the a job?
Hi,
I have prepared a task ( i.e. a procedure is prepare the file and send the same to con

Getting a variable to work in function params
I have this fuction which is inside a class:

Code: public static function generateEmbedCode($

upload image name with extension using php
hi frds..

<input id="file1" type="file" name="file[]" &a

Finding digits in variable containing text, and IDing them
$romanstock = "http://www.remoteprice.com/data.asp?storeid=123&itemcode=456&typ

quick question about System Change Number(SCN) in FlashBack Query topic
i know tht we can get the SCN of the database using flashback concept as follows

SQL>

Inserting multiple records from single form
I've found a number of threads that deal with this issue, but I'm new to php and coding language so

Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi

Please help with code for SMTP authenticated PHP email form
Hello, I'm creating a PHP email form, and for this particular server, I have to use SMTP Authenticat

Using Curl_multi for processing multiple URLs
Hi,

I am at a loss as to how to implement this. I would like to be able to automatically assi

Help with page encoding issue and weird characters
I'm trying to write a screen scraper and when I pull out the lines of the html file that I'm interes

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