我想在选择下拉列表中的选项后更新表。但是,当我单击批准按钮时,数据库中的车牌未更新。有人能帮我吗?谢谢。
<?php
mysql_connect("l","t","")or die(mysql_error()); // connect to server
mysql_select_db("car")or die("Cannot connect to database") ;
$query=mysql_query("Select * from list "); //SQL Query
echo "<table><tr>
<th>Name</th>
<th>Destination</th>
<th>Time</th>
<th>Date</th>
<th>Car Requested</th>
<th>Purpose</th>
<th>Car Approve</th>
<th>Approve</th>
<th>Reject</th>
</tr>";
while($row=mysql_fetch_array($query))
{
if($row['status'] =='Pending'){
echo"<tr>";
echo'<td align="center">'.$row['employee']."</td>";
echo'<td align="center">'.$row['destination']."</td>";
echo'<td align="center">'.$row['time']."</td>";
echo'<td align="center">'.$row['date']."</td>";
echo'<td align="center">'.$row['car']."</td>";
echo'<td align="center">'.$row['message']."</td>";
echo'
<form action="approve.php" method="GET">
<td align="center">
<select name="car_plate">
<option>--Select Car--</option>
<option>WBN 3041</option>
<option>WWW 4545</option>
<option>BBB 1111</option>
<option>CCC 2222</option>
<option>DDD 3333</option>
</select>
</td>
</form>
';
echo'<td align="center"><a href="#" onclick="fapprove('.$row['id'].')">Approve</a> </td>';
echo'<td align="center"><a href="#" onclick="freject('.$row['id'].')">Reject</a> </td>';
echo"<tr>";
}
}
echo"</table>";
?>
<script>
function fapprove(id)
{
var r=confirm("Are you sure you want to APPROVE this record?");
if(r==true)
{
window.location.assign("approve.php?id=" + id);
alert('APRROVED! =)');
}
}
</script>
approve.php
if($_SERVER['REQUEST_METHOD'] == "GET")
{
mysql_connect("l", "r","") or die(mysql_error()); //Connect to server
mysql_select_db("car") or die("Cannot connect to database"); //Connect to database
$id = $_GET['id'];
$car_plate = $_GET['car_plate'];
mysql_query("UPDATE list SET status='Approved' WHERE id='$id'");
mysql_query("UPDATE list SET car_plate='$car_plate' WHERE id='$id'");
答案 0 :(得分:0)
你没有在你的javascript函数中传递carplate编号。使用以下代码
function fapprove(id)
{
var r=confirm("Are you sure you want to APPROVE this record?");
if(r==true)
{
var carPlate = $("#car_plate").val();
window.location.assign("approve.php?id="+id+"&car_plate="+carPlate);
alert('APRROVED! =)');
}
}
将选择下拉列表中的ID添加为<select id="car_plate" name="">
希望它对你有用。如果您需要任何帮助,我已准备好为您提供指导......