SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,446
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Maybe try
    PHP Code:
    $sql "SELECT stock_item, qty FROM wms WHERE stock_item = '" $ItemCode "' AND lot_number = '" $lot_number "'"

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    657
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this and still same output.


    Thank you

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,446
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    It doesn't seem like you would get a syntax error for it, but is the field data type and field length OK?


Bookmarks

Posting Permissions

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