thereaper87 Posted August 22, 2010 Share Posted August 22, 2010 Hello there, I have this bit of code: <?php $host="localhost"; // Host name $un="**"; // Mysql username $password="**"; // Mysql password $db_name="**"; // Database name $tbl_name="weddingpics"; // Table name // Connect to server and select database. mysql_connect("$host", "$un", "$password")or die("cannot connect"); $id = intval($_POST['id']); $sql="DELETE id='$id' FROM $tbl_name WHERE id=$id"; $result=mysql_query($sql); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='weddingcakes.php'>View result</a>"; } else { echo "Error"; } ?> I've tried to reword the delete query but still no avail. If you are wondering where it pulls the `id` variable, it is on the previous page as a hidden attribute. Link to comment https://forums.phpfreaks.com/topic/211444-mysql-delete-query/ Share on other sites More sharing options...
GoneNowBye Posted August 22, 2010 Share Posted August 22, 2010 DELETE FROM Table Name WHERE id=my_picture_id syntax error, thats all Link to comment https://forums.phpfreaks.com/topic/211444-mysql-delete-query/#findComment-1102443 Share on other sites More sharing options...
thereaper87 Posted August 22, 2010 Author Share Posted August 22, 2010 I changed it to this: $sql="DELETE FROM $tbl_name WHERE id=$id"; Still no go. Link to comment https://forums.phpfreaks.com/topic/211444-mysql-delete-query/#findComment-1102450 Share on other sites More sharing options...
Mchl Posted August 22, 2010 Share Posted August 22, 2010 Use mysql_error to see if/what about mysql complains. Link to comment https://forums.phpfreaks.com/topic/211444-mysql-delete-query/#findComment-1102451 Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2010 Share Posted August 22, 2010 At a minimum you are going to need a mysql_select_db('your_db_name_here'); statement or you will need to specify the database name in the query - db_name.table_name Link to comment https://forums.phpfreaks.com/topic/211444-mysql-delete-query/#findComment-1102457 Share on other sites More sharing options...
thereaper87 Posted August 22, 2010 Author Share Posted August 22, 2010 Sweet I just added: $db_name.$tbl_name [/code and it works! Thanks all 3 of you for your help! Link to comment https://forums.phpfreaks.com/topic/211444-mysql-delete-query/#findComment-1102463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.