MySQL DELETE help needed.

Discussion in 'PHP' started by nugis, May 9, 2009.

  1. #1
    This is the link to trigger the code part:
    <a href='?cmd=deletetype3&id=$picid'>Delete</div>
    Code (PHP):
    This query should be done:
    
    if($_GET["cmd"]=="deletetype3"){
    $deletepic = mysql_query("DELETE FROM userbooks WHERE ename = '$ename' AND ID = '$picid'");}
    
    Code (PHP):
    picid = 22 (for example)
    ename = logged user. (bob?)

    Instead of deleting the matching ones, it whipes out the whole table entries. Why is that? Helps appreciated.
     
    nugis, May 9, 2009 IP
  2. aGor

    aGor Member

    Messages:
    80
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    I dont know why it does that.

    But I guess your ID is stored as an int? If so, then you should remove the qoutes(') around $picid in the sql query
     
    aGor, May 9, 2009 IP
  3. nugis

    nugis Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    To ensure that all the variables are correct i tried to post em into the url bar with this piece of code:
    
    if($_GET["cmd"]=="deletetype3"){
    header("Location: index.php?name=$ename&id=$picid");
    }
    
    Code (PHP):
    Results: index.php?nimi=/&%¤#/@gmail.com&id=23
    All the way it should be. Maybe its a some kind of a bug?
     
    nugis, May 9, 2009 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    Try this;


    
    
    <a href='?cmd=deletetype3&id=<?=$picid?>'>Delete</div>
    
    
    PHP:
    
    
    if($_GET["cmd"]=="deletetype3"){
      $deletepic = mysql_query("DELETE FROM userbooks 
                                          WHERE ename = '" . $ename . "' 
                                          AND ID = '" . $_GET['picid'] . "');
    }
    
    PHP:
     
    Weirfire, May 9, 2009 IP
  5. nugis

    nugis Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for your reply but it didnt delete anything.
    No errors, nothing. Did fix that syntax error though.
    Im thinking of having a popup conformation screen and use GET/POST functions there. Done similar things before.
     
    nugis, May 9, 2009 IP
  6. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #6
    I noticed a small mistake in my code;

    Also try the code below and run the echoed query in PHPMYAdmin and see what happens. Might be a table syntax error (e.g. wrongly named field etc)

    
    
    
    if($_GET["cmd"]=="deletetype3"){
      $qry = "DELETE FROM userbooks
                                          WHERE ename = '" . ename . "'
                                          AND ID = '" . $_GET['picid'] . "'";
      echo $qry;  
      $deletepic = mysql_query($qry);
    } 
    
    
    
    PHP:
     
    Weirfire, May 9, 2009 IP