PHP - MySQL Delete Row

Hi All, Thanks for your excellence assistance so far! :smiley: I have another question… I am trying to delete a row in MySQL with PHP, here is my code:

[php]

<?php $host="localhost"; $username="root"; $password=""; $db_name="php_login"; $tbl_name="users"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $id=$_GET['id']; $sql="DELETE * FROM $tbl_name WHERE id='$id'"; ?>

[/php]

Can anyone tell me why this is not working? Thanks In Advance! :smiley:

Hey…

Are you getting any error, and if yes, what is it?

If not, check whether your $_GET[‘id’] is set by typing echo $id; after it. If nothing happens, then there is a problem with the sending of your ‘id’ variable.

Hope this helps,

Ramanakumar

You must execute $sql,

Add
mysql_query($sql);
at the end of the code.

Hi There, That hasn’t seemed to worked, I have tried using this code:

[php]

<?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="php_login"; // Database name $tbl_name="users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $id = $_GET['id'] or die("VARIABLE IS GAY"); mysql_query("DELETE * FROM users WHERE id='$id'") or die("Error Deleting The User"); echo "Done"; ?>

[/php]

I then get the or die(“Error Deleting The User”);

Thanks, James

Problem fixed, thanks for all your help :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service