error when trying to delete

Discussion in 'PHP' started by reubenrd, Apr 18, 2009.

  1. #1
    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?
     
    reubenrd, Apr 18, 2009 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    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.
     
    PoPSiCLe, Apr 18, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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 =" ?
     
    SmallPotatoes, Apr 18, 2009 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Didn't even catch that one :D But he could also just remove the if/else statement with the $sql in it - should work just fine that way too.
     
    PoPSiCLe, Apr 19, 2009 IP