0

This is my Jquery that is capable of Inserting

$(function(){
$(document).on('click', '#addRefBtn', function(e){
   var get_input = $('#qr_ref').val();
   var get_po = $('#get_po').val();
   location.reload();
     $.ajax({
            type: 'POST',
            url: 'validate_qr.php',
            data: {
            qr_code:get_input,
            po_ID: get_po
            },
           success: function(result){
           // console.log(result);
           },
          error: function(result){
          }
       });
     });
   });

and this is my Url in ajax that is compose of my query that is inserting and also I want to update

                        $query = $conn->prepare("INSERT INTO product_sales (product_id, client_id, po_ID, unitPrice, sales_date, updated_date,                                   invoiceTerminated, reference_no, status) 
                                             VALUES (:product_id, :client_id, :po_ID, :unitPrice, :sales_date, :updated_date, :invoiceTerminated, :reference_no, :status)");
                    $query->execute([
                                        'product_id'=> $product_id, 
                                        'client_id'=> $client_id, 
                                        'po_ID'=> $po_ID, 
                                        'unitPrice'=> $etc_price,
                                        'sales_date'=> $date,
                                        'updated_date'=> $updated_date,
                                        'invoiceTerminated'=> $invoiceTerminated,
                                        'reference_no'=> $New_ref_no,
                                        'status'=> $status
                                    ]);

                    $queryUpdate = $conn->prepare("UPDATE backup_sales t1 
                                                   JOIN product t2 ON (t1.model_id = t2.model_id) 
                                                   SET t1.status = '1', 
                                                    t2.prod_status = '1' 
                                                   WHERE t1.po_ID = ':po_ID'
                                                   AND t2.model_id = ':product_id'");

                    $queryUpdate->execute(['po_ID'=>$po_ID, 'product_id'=>$product_id]);

Is my approach correct? Am i missing something? Kindly correct me, thanks.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

1

Don't quote placeholders, that makes them strings, not placeholders. In your UPDATE the WHERE clause is doing this,

WHERE t1.po_ID = ':po_ID' AND t2.model_id = ':product_id'

should be:

WHERE t1.po_ID = :po_ID AND t2.model_id = :product_id

so the driver can replace them with the values. That also should be throwing an error because you have 2 values it is trying to bind but no placeholders to bind it to.

user3783243
  • 5,368
  • 5
  • 22
  • 41
  • Its kinda weird because I don't got any error, with these incorrect approach internal 500 error is the common error. – Robert Capistrano Sep 11 '18 at 03:56
  • It is not a PHP syntax error. The PHP will compile and execute fine. Take a look at http://php.net/manual/en/pdo.error-handling.php – user3783243 Sep 11 '18 at 03:57
  • 1
    Update is working now, thanks a lot! I can't mark it check yet because of post time requirement. I thought I got a wrong approach to this. Thanks a lot! – Robert Capistrano Sep 11 '18 at 03:58