Hello I am trying to make a form which will delete the information from mysql database. Basically when user enters the id number of the row, when the press delete it should delete the row of information of that id number. Heres the form im using: <form action="functions/deleteseason.php" method="post"> <p>ID: <INPUT TYPE="text" NAME="deleteseason"></p> <INPUT TYPE="submit" value="Delete Season"> </form> Heres the php code im using to delete it. <?php $con = mysql_connect("hostname","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("getheroe_getheroes1", $con); $del = mysql_real_escape_string($_POST['deleteseason']); mysql_query("DELETE FROM season WHERE id='$del'"); if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con) ?> And when i press the submit button i get this error: Error: Query was empty Why is this doing this?
Seems a bit weird - tested the form and such now, and it returns the value entered in the text-field, so it is not that which is the problem. Could you maybe echo the $del-variable to check and see if it returns something? If it does, it is something wrong with the query itself - if, for instance, the ID chosen by the user isn't in the database, you could get this in return.
What do you think the value of $sql is when it tries to execute that second, spurious call to mysql_query()? How about changing the first "mysql_query()" to a "$sql =" ?
Didn't even catch that one But he could also just remove the if/else statement with the $sql in it - should work just fine that way too.