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
Need some ideas as to how to go about sorting this array...
Here's how the array's are created..
Code: <?php
while ($x = readdir($dp)) {
rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded
Casting Decimals in Oracle
This code worked as a query in DB2, but I am not sure what the syntax is for casting decimals in Ora
limitations on array_unique()
Does any one know what/how imitations are applied to array_unique? I have an issue where no matter h
extract data
Code: <div class="post hentry uncustomized-post-template">
str_replace help
Hey there,
I'm a PHP newb, I'm having troubles with the str_replace function. I want to clean
Sessions Value Not Saved
Hi,
Im making a login form and im using this code:
Code: if($login=="true"){
frames get header location..
i have two frames, one top, one bottom. how do i do a form on the bottom frame that gives me the ur
Finding digits in variable containing text, and IDing them
$romanstock = "http://www.remoteprice.com/data.asp?storeid=123&itemcode=456&typ
DATEDIFF Question
First time post, and of course it is a help question.
I am using a WP plug-in to display prev