1

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!

Jack Sniper
  • 389
  • 1
  • 8
  • 20

2 Answers2

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");
      }  
    });
Code Lღver
  • 15,573
  • 16
  • 56
  • 75
  • Wow I was way off trying to declare the data. I changed the alert to returnData and its feeding me back an error. So the php file is being access at least, but I'm still not certain if the url is receiving the variables. – Jack Sniper Aug 28 '13 at 05:54
  • @JackSniper you can using `$_GET` method that is used to get the data by **get** method replace that by `$_REQUEST` and you can check that by echoing that variables in php file. – Code Lღver Aug 28 '13 at 05:59
1

Would it not be enough to define your URl like so: url: "dropship_process.php?pID="+ pid +"&drop-shipping="+ dropshippingid

woolagaroo
  • 1,542
  • 2
  • 22
  • 31