<?php
$status=&$_POST['status'];
$from=&$_POST['date_from'];
$to=&$_POST['date_to'];
$conn=mysqli_connect('localhost','root','','punbus') or die("Database not connected".mysqli_error());
if(isset($_POST['sub'])){
$ins="insert into driver_status(driver_name,status,date_from,date_to)
select Driver_name,'$status','$from','$to' from driver_master";
if(mysqli_query($conn,$ins)){
echo "added";
}
else{
echo "NOT".mysqli_error($conn);
}
}
$sel='select Driver_name from driver_master';
$query=mysqli_query($conn,$sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr>";
echo "<td>".$row['Driver_name']."</td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
?>
<td>
<select name="status">
<?php
while($row1=mysqli_fetch_assoc($query1)){
$st=$row1['d_status'];
echo "<option value='$st'>$st</option>";
}
?>
</select>
</td>
<?php
echo "</tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
這是我的代碼。我想將從4下拉列表中選擇的選項保存到mysql。當我提交表單時,從最後一個框中選擇的值將被保存在mysql表的所有行中。現在,請告訴我該怎麼辦? 我正在從數據庫表中正確地下拉框值,所以問題是什麼?如何在php中將選定值從下拉列表中保存到mysql中
它也不起作用。 status_ $麻木是正確的選擇標籤? – 2015-03-02 07:22:30
'status_ $ numb'不是標記,它是選擇名稱屬性的值..它將在您的選擇中給出名稱'select_1,select_2,select_3,select_4'。並在你的PHP中,你可以通過'$ _POST ['select_1'] ..etc'來訪問這些值。所以你的4選擇不具有相同的名稱,但名稱不同。 – check 2015-03-02 07:31:00
我已經試過這個,但它不起作用 – 2015-03-02 08:27:50