我在一个简单的 PHP MySQL 项目中遇到问题。当我尝试从选择选项中获取记录时,它只提供 ID。我也希望传递来自选择的值。
<form class="form-style-9" method="POST" action="function.php?type=updatedistrict">``
<ul>
<li>ID:
<input type="hidden" name="dist_id" class="field-style field-full align-none" value="<?php echo $ids;?>" readonly />
</li>
<li>District Name:
<input type="text" name="name" class="field-style field-full align-none" value="<?php echo $names;?>" />
</li>
<li>Postal Code:
<input type="text" name="code" class="field-style field-full align-none" value="<?php echo $codes;?>"/>
</li>
<li>Province
<select name="province_id" class="form-control">
<option value="">Select Province</option>
<?php
$sql = mysqli_query($conn, "SELECT id, province From province");
$row = mysqli_num_rows($sql);
while ($row = mysqli_fetch_array($sql)){
echo "<option value='". $row['id'] ."'>" .$row['province'] ."</option>" ;
}
?>
</select>
<li>
<input type="submit" value="Update" name="submit" />
</li>
</ul>
</form>
这是更新功能代码:
case 'updateprovince':
if (isset($_POST['submit'])) {
$id = $_POST['dist_id'];
$prov_id= $_POST['province_id'];
$query=$conn->query("UPDATE province SET province='$prov_id' where id='$id'");
if ($query) {
echo '<script> window.location.replace("province.php");
</script>';
}
else
{
echo "issue";
}
}
break;
GCT1015