我正在尝试在我的选择框中发生更改时更新我的数据库。我调用来处理所有内容的 php 文件运行良好。继承人的代码:
<?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";
}
?>
我所要做的就是在 url 中定义两个变量,我的 id 条目将在 products 表下更新,例如:www.website.com/dropship_process.php?pID=755&drop-shipping=16
这是调用 dropship-process.php 的 jquery 函数:
$.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");
});
}
});
});
我在想我如何错误地定义了我的数据。这是我第一次使用序列化以外的任何东西,所以任何指针都将不胜感激!