我想使用下拉菜单更新我的数据库 我能找到的大多数ajax都是为了退出数据。有人可以帮忙。
我的php updatestatus.php页面是
include 'includes/session.php';
include 'includes/db_connection.php';
include 'includes/functions.php';
$status = $_POST['status'];
$id = $_POST['id'];
$sql = "UPDATE orders SET
status = '$status'
WHERE id = $id";
我在order.php中的选择框是
<select name="status" id="id" onchange="updateStatus((this.value),<?php echo $row['id']; ?>)">
<option value="<?php echo $row['status']; ?>"><?php echo $row['status']; ?></option>
<option value="Order Placed">Order Placed</option>
<option value="Processing">Processing</option>
<option value="Dispatched">Dispatched</option>
</select>
我在order.php中的JavaScript是
function updateStatus(status, id){
var url = "updatestatus.php";
if (window.XMLHttpRequest) { // branch for native XMLHttpRequest object
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open('POST', url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(data);
}else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version
req = new ActiveXObject('Microsoft.XMLHTTP')
if (req) {
req.onreadystatechange = processReqChange;
req.open('POST', url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(data);
}
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
将data
定义为:
var data = "status="+status+"&id="+id;
还要将您的sql更改为:
$sql = "UPDATE orders SET
status = '".$status."'
WHERE id =". $id;