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
More pug propaganda.
http://www.youtube.com/watch?v=8Kkrmubsgf8
The commercial is definitely worth watching pug aw
Echo-ing MySQL content and Keep Formatting?
I have data in my MySQL such as:
QuoteBlah blah
Blah blah
etc
but when i ech
Backflush
I am looking for a report in SAP that would give me a list of all parts that are populated with a ba
Call db table from any PHP file
Hi,
I want to be able to call a database table that will be setup in another file called init
PHP hyperlinks generator - HELP plz
Hi
I need some help to get this done using php:
1 - I have few hyperlinks say 500
how to configure ADS in ABAP instance
Hi All,
I am working on r/3 4.7 ABAP system.Can we configure ADS(adobe document services)
Echoing a Variable from a Object
How do I get a variable from the new User Class to echo out in this clasS?
class MyApp
{
Question about GD library
I am trying to make an image that shows a random quote from my database.
However I want t
Read from a text file after a specific word
Hi all.
I have a text file that looks like the one below.
I know how to open the text fi
Need a Timecode Class...
Not a Time Stamp, Time Code. Format is a bit different. HH:MM:SS:FF where FF is Frames. I dont re