Jump to content

Wrong Key.error: Query Was Empty


Gatsu
 Share

Recommended Posts

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...