我想使用下拉菜单更新我的数据库 我能找到的大多数 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);
}
}
}