Gatsu Posted February 15, 2010 Share Posted February 15, 2010 Hi, I'm trying to add a password for deleting ads on my website so when people add something there will be a random key called delkey in my DB.I use this form: <form name="del" method="post" action="del.php?id=<?php echo $add['id']; ?>"><input name="delkey" type="text" /><input name="Del" type="submit" value="Delete" /></form> And this is del.php: <?php//header('HTTP/1.1 301 Moved Permanently');//header('Location: index.html');include("config.php");if ($_POST['delkey']==$_GET['delkey']) {$sql = "DELETE FROM addacc WHERE id=".$_GET['id']."";echo $_POST['delkey'];}else {echo "Wrong key.";}if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }mysql_close($con)?> Why do I get this message when I try to enter the key:"Wrong key.Error: Query was empty"and when I enter no key the add is deleted. Link to comment Share on other sites More sharing options...
Ingolme Posted February 15, 2010 Share Posted February 15, 2010 Because that's exactly what your code is doing, look carefully: if ($_POST['delkey']==$_GET['delkey']) { $sql = "DELETE FROM addacc WHERE id=".$_GET['id'].""; echo $_POST['delkey'];} else { // The condition was false, so "Wrong key." Is printed" echo "Wrong key.";}// $sql is not defined because the previous condition was falseif (!mysql_query($sql,$con)) { // Therefore 'mysql_error()' returns "Query was empty" // Because the query really is empty. die('Error: ' . mysql_error());} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.