gpt4 book ai didi

php mysql 从下拉列表中获取值打印到屏幕

转载 作者:行者123 更新时间:2023-11-30 01:19:45 26 4
gpt4 key购买 nike

我试图从表单内的下拉列表中获取值并将该值打印到屏幕上。从设置为“自身”的表单操作。在 mysql 语句中使用此变量

//load drop downs
$result = mysqli_query($db, "SELECT * FROM actor_id");

//loads actor_name to drop down
print("<select name=\"actor_name\">\n");
while($row = mysqli_fetch_array($result))
{
print ("<option value=" . $row[0] . ">" . $row[1] . "</option>");
$row = mysql_fetch_row($result);
}
print("</select>");
//close DB
mysqli_close($db);

?>
<form method = "post" action="actors.php" >

<br />
<input type="hidden" name="stage" value="1" />
<input type="submit" name="submit" value="Search" >
</form>

//after submit reloads this
if(isset($_POST['actor_name']))
{
$star = $_POST['actor_name'];
print "Star: " . $star;
}//want to use this variable in a mysql statement

最佳答案

我认为您想显示在​​本次尝试的下拉列表中选择了POST actor,

您必须在表单元素添加 Actor 列表,例如

<form method = "post" action="actors.php" >
<?php
print("<select name=\"actor_name\">\n");
while($row = mysqli_fetch_array($result))
{
$sel='';
if($row[0]==$_POST['actor_name'])
$sel='selected="selected"';
print ("<option value=" . $row[0] . " ".$sel.">" . $row[1] . "</option>");
//$row = mysql_fetch_row($result); remove this line it has no meaning
}
print("</select>");
?>
..........

关于php mysql 从下拉列表中获取值打印到屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18682665/

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