Query was empty??

Discussion in 'PHP' started by livewirerules, Oct 10, 2007.

  1. #1
    im tryn to delete a complete row from the database but when i click the delete link i get this error
    Query was empty.can someone pls help me

    <?php
    /*
    deletemovie.php
    delete movies from the database
    */
    session_start();
    ob_start();
    include("includes/conn.php");
    include("auth.php");
    include("../template/header.html");
    
    
    //$id=$_GET['memberid'];
    
    //$sq1="SELECT * FROM `movie_info` WHERE `memberid`='$_GET[memberid]'";
    //$result=mysql_query($sql) or die(mysql_error());
    //$row=mysql_fetch_array($result);
    
    
    $sql="DELETE * FROM `movie_info` WHERE memberid = '$_GET[memberid]'";
    $result=mysql_query($sql) or die(mysql_error());
    echo "Deleted";
    header("Location:manage_movies.php");
    exit();
    ?>
    Code (markup):
     
    livewirerules, Oct 10, 2007 IP
  2. *louie*

    *louie* Peon

    Messages:
    48
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    give this a go:

    
    <?php
    /*
    deletemovie.php
    delete movies from the database
    */
    session_start();
    ob_start();
    include("includes/conn.php");
    include("auth.php");
    include("../template/header.html");
    
    
    $id=!empty($_GET['memberid']) ? $_GET['memberid'] : "";
    
    if($id == ""){
    echo "no id";
    die();
    }else{
    
    $sql="DELETE FROM `movie_info` WHERE memberid = '".$id."'";
    $result=mysql_query($sql) or die(mysql_error());
    echo "Deleted";
    header("Location:manage_movies.php");
    exit();
    }
    ?>
    
    PHP:
     
    *louie*, Oct 10, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    No need for the "else" when you die in the "if". :)

    And remember to use intval() and mysql_real_escape_string() to prevent MySQL injections.


    Ah yeah, and as for the error, remove the asterisk from your query. DELETE queries don't support these as you can't delete fields. (Not using DELETE queries at least)

    EDIT:

    And on a further note, you cannot redirect using header() after you've sent output to the browser. So remove the echo as well.
     
    nico_swd, Oct 10, 2007 IP
  4. mikemotorcade

    mikemotorcade Peon

    Messages:
    645
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yeah, a bettter way to go about notifying the user that the row was deleted would be something like this:

    header("Location:manage_movies.php?message=Deleted");
    PHP:
    and then out this code in manage_movies.php where you want the message to display:

    
    <?php
    if ($_GET['message']) {
       echo "<h2>" . $_GET['message'] . "</h2>";
    }
    ?>
    
    PHP:
    or you can do whatever formatting you want, doesn't have to be H2
     
    mikemotorcade, Oct 10, 2007 IP