Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    713
    Thanks
    165
    Thanked 0 Times in 0 Posts

    php mysql error for the right syntax to use near

    Hi..

    I have this code:

    PHP Code:
    $Approved = isset($_POST['priority']);
    if (
    $Approved)
    {
        
    $lot_number $_POST['lot_number'];
        
    $sr_number_ $_POST['sr_number_'];
        
    $SubQty $_POST['SubQty'];
        
    $ItemCode $_POST['ItemCode'];
        
    $picked_by $_POST['picked_by'];
        
    $sql "SELECT stock_item, qty FROM wms WHERE stock_item = '$ItemCode' AND lot_number = '$lot_number'";
    $res mysql_query($sql$con) or die(mysql_error());

    $row mysql_fetch_assoc($res);

    $stock_item $row['stock_item'];
    $qty $row['qty'];

    if(
    $qty >= $SubQty){

    $output $qty $SubQty;
    $qty_withdraw '0.00';
    }
    else{
    $output '0.00';
    $qty_withdraw $SubQty $qty;
    }   

    error:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MAT-CHE-0040'' at line 2

    but when I echo the $sql;
    the output is:

    SELECT stock_item, qty FROM wms WHERE stock_item = 'MAT-CHE-0040' AND lot_number = 'LO120601002';

    and it works.

    I don't know why in php the sql query got an error:

    How can I remove that error?

    Thank you so much

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Change
    PHP Code:
    $res mysql_query($sql$con) or die(mysql_error()); 
    to
    PHP Code:
    $res mysql_query($sql$con) or die(mysql_error(). '<br>'.$sql); 
    and post the output here.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •