Query error - SQL syntax, please help.

Discussion in 'MySQL' started by Devana, Sep 16, 2009.

  1. #1
    I'm working on a new website and was about to add some items via my admin panel, and I got this error:

    The code is here (somewhere), I think:

    $itmname=$_POST['itmname'];
    $itmdesc=$_POST['itmdesc'];
    $weapon=abs((int) $_POST['weapon']);
    $armor=abs((int) $_POST['armor']);
    if($_POST['itmbuyable'] == 'on') { $itmbuy=1; } else { $itmbuy=0; }
    $db->query("DELETE FROM items WHERE itmid={$_POST['itmid']}",$c);
    $efx1=$db->escape(serialize(array("stat" => $_POST['effect1stat'], "dir" => $_POST['effect1dir'], "inc_type" => $_POST['effect1type'], "inc_amount" => abs((int) 
    
    $_POST['effect1amount']))));
    $efx2=$db->escape(serialize(array("stat" => $_POST['effect2stat'], "dir" => $_POST['effect2dir'], "inc_type" => $_POST['effect2type'], "inc_amount" => abs((int) 
    
    $_POST['effect2amount']))));
    $efx3=$db->escape(serialize(array("stat" => $_POST['effect3stat'], "dir" => $_POST['effect3dir'], "inc_type" => $_POST['effect3type'], "inc_amount" => abs((int) 
    
    $_POST['effect3amount']))));
    $m=$db->query("INSERT INTO items VALUES('{$_POST['itmid']}',{$_POST['itmtype']},'$itmname','$itmdesc',{$_POST['itmbuyprice']},{$_POST['itmsellprice']},$itmbuy, 
    
    '{$_POST['effect1on']}', '$efx1', '{$_POST['effect2on']}', '$efx2', '{$_POST['effect3on']}', '$efx3', $weapon, $armor)");
    print "The {$_POST['itmname']} Item was edited successfully.";
    stafflog_add("Edited item {$_POST['itmname']}");
    }
    PHP:
    Could anyone please take a look and see if there's an error or please let me know what can be the trouble and maybe a solution.
    It would be absolutely much appreciated :)
     
    Devana, Sep 16, 2009 IP
  2. aaron_nimocks

    aaron_nimocks Im kind of a big deal Staff

    Messages:
    5,563
    Likes Received:
    627
    Best Answers:
    0
    Trophy Points:
    420
    #2
    What are you deleting here?

    $db->query("DELETE FROM items WHERE itmid={$_POST['itmid']}",$c);
    PHP:
    Just looking at it for a second it seems wrong, there should be something between DELETE and FROM. Most likely its supposed to be a * in there.
     
    aaron_nimocks, Sep 16, 2009 IP
  3. Devana

    Devana Well-Known Member

    Messages:
    987
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Thanks for your reply. I'm not sure to be honest, I've tried to contact the script owner, but he's not replying.
    I though DELETE FROM was the same type as INSERT INTO, and it was supposed to be like this...? :confused:
     
    Devana, Sep 16, 2009 IP
  4. Lavee

    Lavee Well-Known Member

    Messages:
    234
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Delete query is good. You have an issue in the insert query

    $m=$db->query("INSERT INTO items VALUES('{$_POST['itmid']}',{$_POST['itmtype']},'$itmname','$itmdesc',{$_POST['itmbuyprice']},{$_POST['itmsellprice']},$itmbuy, 
    
    '{$_POST['effect1on']}', '$efx1', '{$_POST['effect2on']}', '$efx2', '{$_POST['effect3on']}', '$efx3', $weapon, $armor)");
    
    Code (markup):
    You cannot have a line break in the middle of of the query.
    Try removing that blank line.
    If that does not work, try this
    $m=$db->query("INSERT INTO items VALUES('{$_POST['itmid']}',{$_POST['itmtype']},'$itmname','$itmdesc',{$_POST['itmbuyprice']},{$_POST['itmsellprice']},$itmbuy, ".
    " '{$_POST['effect1on']}', '$efx1', '{$_POST['effect2on']}', '$efx2', '{$_POST['effect3on']}', '$efx3', $weapon, $armor)");
    
    Code (markup):
    Thanks

    Lavee
     
    Lavee, Sep 16, 2009 IP
  5. Devana

    Devana Well-Known Member

    Messages:
    987
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    130
    #5
    Thanks for your advice, but unfortunetely non of the above worked. Do you have any other ideas? :)
     
    Devana, Sep 18, 2009 IP
  6. Devana

    Devana Well-Known Member

    Messages:
    987
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Never mind. Problem fixed! :)
     
    Devana, Sep 18, 2009 IP