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

problems with php variables in mysql query
i can't seem to get the following query to work.

select $q1c from $vote_rate where id = $re

Internal class functions don't seem to get executed.
Hi. Can someone please put me out of my misery on this. I don't write much PHP and this has me baffl

Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:
Code: [General]
Online=0
I wou

what business processes?
Hi,

A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)

PHP Search Issue
Hi, I am using the following code to search and return flights from a database. The user searches by

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

Mass activity scheduling
Hi experts,

Im facing some problems to deal with mass activity jobs.
When I run some

UPLOAD IMAGES NOT WORKING!
Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbna

Select Lists into MYSQL
Hello All, I am new to PHP @ 1 week. So borrowing code anywhere I can. I am making progress, but h

Problem with umlauts and UTF-8
Hello every1,

I'm creating my own little CMS at the moment and got some problems with the cha

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