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
29
Other forums
calendar dates and hours compare problem
i have a calendar in wordpress, everything works great except that i can make 2 meetings at the same
curl javascript problem
Hi Experts.
I'm new curl and wanna to get some info from this http://www.amadeus.net/
when
Get ID from Database when Posting with a HTML Form
I have a form I am submitting to a MySql database. Each product has an ID # attached to it that auto
string to currency format
Hi guys...
Actually I chunk out some data from txtfile and one of the data contains amount va
Line break?
Hi, I'm new to the forum and new to php. I'm not sure if I'm using the correct terminology so here i
Am I setting up my sites oldschool?
Ok,
When I create a site I open a basic template that I have created that consists of a css f
Problem displaying "scraped" XML data
I'm basicly having trouble displaying XML data scraped from an URL using cURL.
What the code
Save cookie to DB
I'm working on a pixel tracking script for an incentive website and I need to use an ASP script to s
Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the
Deleted Delivery but material wont return
We deleted a delivery but the material its still pending.
We made a reverse goods movemen