Forum Moderators: coopster

Message Too Old, No Replies

delete record

how do I delete a record

         

YnotInTX

6:29 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



This is my "delete.php" and this "todo/delete.php?id=64" an example of a link to it generated from the index.php page. When the delete link is clicked the next page is blank and nothing is deleted. What have I done wrong? Thank you in advance!

<?
include("dbinfo.inc.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$id="delete from todo where id='$id'";
mysql_query($id);

mysql_close();
?>

dreamcatcher

7:16 pm on Mar 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld YnotInTX :)

Do you have register globals on or off? And what about short tags?

Try changing your code to:


<?php
include("dbinfo.inc.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="delete from todo where id='".$_GET['id']."' LIMIT 1";
mysql_query($query);

mysql_close();

echo "ID " . $_GET['id'] . " deleted!";

?>

You don`t really need to use mysql_close() as the connection is closed anyway once the query ends. I have left in it place though. Also, its not a good idea to name your query variable ($id) the same as your variable that already holds data as it will overwrite it.

YnotInTX

8:05 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



I found this site this morning in trying to learn php and do a simple "ToDo" script. WHAT A GREAT SITE! Thank you!

dreamcatcher

11:55 pm on Mar 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You`re welcome. :)