0

我试图从表单中的下拉列表中获取值并将该值打印到屏幕上。从设置为“自身”的表单操作。在 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
4

1 回答 1

0

我想你想表明这个POST演员是在drop down list这个尝试中被选中的,

你必须add actor list喜欢form element

<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>");
    ?>
    ..........
于 2013-09-08T10:31:38.780 回答