gpt4 book ai didi

php - 如何更新下拉列表中的特定行?

转载 作者:行者123 更新时间:2023-11-30 22:17:48 24 4
gpt4 key购买 nike

我想在选择下拉列表中的选项后更新表格。但是,当我点击批准按钮时,数据库中的车牌没有更新。有人能帮我吗?谢谢。

<?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>

批准.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'");

最佳答案

您没有在 javascript 函数中传递车牌号。使用下面的代码

     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="">

希望它对你有用。如果您需要任何帮助,我随时准备指导您...

关于php - 如何更新下拉列表中的特定行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37651633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com