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
very easy question about SQL info
Hello,
I think that I have a very easy question.
I know how to create a form using php SQL and
unserialize help, getting errors
hi all ,
I got a form with 6 fields (2 input and 4 select box), when the page loads one block is
Array help
Hello i got this code to fetch data from database but it is not working it displays
7
Array
Need help in Generating Combinations
Need help generating all possible combination of names in an array
Lets say i have the follow
Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t
Add weeks in a query?
I have a SQL that summarizes the quantity per week. The weeks that has no value does not exist in th
Please help understand this code
I noticed the index page on my site was modified this morning and found this code inserted at the bo
contact form - output to page and email
I have the following in my controller:
$message['name'] = htmlentities(strip_tags(trim($_POST
Session variable help
I'm having a very troubling issue. Maybe I'm just looking over something but I have looked at the co
Update Database
Hi All,
I have a problem with this:
Code: [Select]<?php
session_start();