| | |
Simple delete problems.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2007
Posts: 10
Reputation:
Solved Threads: 0
Hi all, I'm just learning how to delete records from a test table but I'm having some problems with it. I'm not sure exactly but it looks like it is deleting the last row from the table no matter which record is clicked on. It also appears that it is deleting all records after the record clicked on but excluding that one. If that makes sense!. Anyway here is the code I got from a tutorial on the net;
Any help is appreciated.
PHP Syntax (Toggle Plain Text)
<?php $dbhost='localhost'; $dbusername='root'; $dbname = 'test'; mysql_connect ($dbhost, $dbusername); mysql_select_db($dbname) or die('Cannot select database'); $query = "SELECT * FROM test4"; $result = mysql_query($query) or die('Error, query failed'); if(!isset($cmd)){ while($row = mysql_fetch_array($result)) { $id = $row["id"]; echo "<strong> tom</strong>: {$row['Tom']}</p>"; echo "<strong> id</strong>: {$row['id']}</p>"; echo "<p><a href='?cmd=delete&id=$id'>delete</a></p>" ; } } if($_GET["cmd"]=="delete") { $sql = "DELETE FROM test4 WHERE id=$id"; $result = mysql_query($sql); } ?>
Any help is appreciated.
•
•
Join Date: Jan 2007
Posts: 37
Reputation:
Solved Threads: 3
Try changing your query to:
Let me know if it works
PHP Syntax (Toggle Plain Text)
$sql = "DELETE FROM test4 WHERE id={$_GET['id']}";
Let me know if it works
![]() |
Similar Threads
- Runtime class (Java)
- Simple Delete problem (PHP)
- Help w/ simple ADO.NET statements.. (VB.NET)
- Weird, weird problems with fstream (C++)
- Is it safe to delete ASP.NET account under users? (Windows NT / 2000 / XP)
- dubble delete (C++)
Other Threads in the PHP Forum
- Previous Thread: youtube
- Next Thread: How can i pick a random sixdigit numbers in php
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner beneath binary broadband broken button cakephp checkbox class cms code compression countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html httppost image include insert integration ip javascript joomla limit link links login mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion remote script search searchbox server session sessions sms smtp source space sql strip_tags survey syntax system table tutorial update upload url validator variable video virus votedown web website window.onbeforeunload=closeme; youtube





