skip to Main Content

I’m trying to update my database on the event of a change in my select box. The php file I’m calling on to process everything, works perfectly. Heres the code for that:

<?php

$productid = $_GET['pID'];
$dropshippingname = $_GET['drop-shipping'];

$dbh = mysql_connect ("sql.website.com", "osc", "oscpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("oscommerce");

$dropshippingid = $_GET['drop-shipping'];


$sqladd = "UPDATE products SET drop_ship_id=" . $dropshippingid . "
WHERE products_id='" . $productid . "'";

    $runquery = mysql_query( $sqladd, $dbh );
        if(!$runquery) {
            echo "Error";
        } else {
            echo "Success";
        }


?>

All I have to do is define the two variables in the url, and my id entry will be updated under the products table, ex: www.website.com/dropship_process.php?pID=755&drop-shipping=16

Here is the jquery function that is calling dropship-process.php:

$.urlParam = function(name){
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}


$('#drop_shipping').change(function() {
    var pid = $.urlParam('pID');
    var dropshippingid = $(this).val();

    $.ajax({  
      type: "POST",  
      url: "dropship_process.php",  
      data: '{' +
        "'pID':" + pid + ','
        "'drop-shipping':" dropshippingid + ',' +
        '}',
      success: function() {  
        alert("success");
     });  
     }  
    });  

});

I’m thinking that I defined my data wrong some how. This is the first time I’ve ever used anything other than serialize, so any pointer would be appreciated!

2

Answers


  1. Your ajax code is not correct. replace your ajax code by below code:

     $.ajax({  
          type: "POST",  
          url: "dropship_process.php",
          dataType: 'text',
          data: {"pID": pid,'drop-shipping': dropshippingid},
          success: function(returnData) { 
            alert("success");
          }  
        });
    
    Login or Signup to reply.
  2. Would it not be enough to define your URl like so:
    url: “dropship_process.php?pID=”+ pid +”&drop-shipping=”+ dropshippingid

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search