我必须遵循以下代码:
<select class="form-control" name="user">
<?php
$sql = "SELECT * FROM user ORDER BY lastname";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?><option><?php echo $row["firstname"] . " " . $row["middlename"] . " " . $row["lastname"]; ?></option><?php
}
} else {
}
?>
</select>
表单的方法是get。我希望用户ID在get中设置,而不是现在发生的,firstname + Middlename + Lastname。所以我不想:webpage.php?user = firstname + middlename + lastname但我想要webpage.php?user = $ id
答案 0 :(得分:0)
请在选项中取值属性,请尝试此代码。因为您没有传递用户ID。 请在值中输入正确的字段,因为我不知道表中用户ID字段的名称,所以请更改
<select class="form-control" name="user">
<?php
$sql = "SELECT * FROM user ORDER BY lastname";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<option value="<?php echo echo $row["id"]; ?>"><?php echo $row["firstname"] . " " . $row["middlename"] . " " . $row["lastname"]; ?>
</option>
<?php
}
}
else {
}
?>
</select>
选项&GT;