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
DB2 for z/OS, LUW, iSeries
Hello,
In this forum a lot of threads related to other members of the DB2 family than DB2 for z/OS
Question about GD library
I am trying to make an image that shows a random quote from my database.
However I want t
Show message after entering data
Hello Colleagues
I would like to display messages after entering the data example: "
dat
Calender Not Opening
The following code is not loading the javascript calender in another window. It's not doing anything
Multidimensional array problems in $_POST
I'm having trouble with a three-dimensional $_POST array. It starts as a two-dimensional array on th
whats wrong with my code please help!!!
this is the error
Warning: mysql_close(): supplied argument is not a valid MySQL-Link res
Connect to database that isn't localhost
I am currently doing a small script for a company that doesn't have mySql support on there hosting.
Serial number of exernal hard disk/Thumbdrive
Hi guys,
I am new tio java networking concepts.Please tel me how to get Serial
number of exernal
Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?
Tracking Unique Clicks
Hi guys and gals,
Basically I have a database which tracks clicks on my outbound links, I do