为什么我无法将错误显示在select
帖子下面的代码上
PHP验证:
if ($movie == "select") {
$errormovie .= 'Please select a favourite movie';
}
HTML:
<select name='movie' id="movie">
<option value="select" >Select your favourite movie:</option>
<option value="Smokey and the Bandit 1977" <?php selected(@$movie, 1) ?>>Smokey and the Bandit 1977</option>
<option value="Good Morning, Vietnam " <?php selected(@$movie, 2) ?>>Good Morning, Vietnam </option>
<option value="Big Trouble in Little China 1986" <?php selected(@$movie, 3) ?>>Big Trouble in Little China 1986</option>
<option value="Dead Poets Society 1989" <?php selected(@$movie, 4) ?>>Dead Poets Society 1989</option>
<option value="Braveheart 1995" <?php selected(@$movie, 5) ?>>Braveheart 1995</option>
<option value="Black Sheep 1996" <?php selected(@$movie, 6) ?>>Black Sheep 1996</option>
<option value="What Dreams May Come 1998" <?php selected(@$movie, 7) ?>>What Dreams May Come 1998</option>
<option value="Patch Adams 1998" <?php selected(@$movie, 8) ?>>Patch Adams 1998</option>
<option value="The Green Mile 1999" <?php selected(@$movie, 9) ?>>The Green Mile 1999</option>
<option value="Jakob the Liar 1999" <?php selected(@$movie, 10) ?>>Jakob the Liar 1999 </option>
<option value="The Skulls 2000" <?php selected(@$movie, 11) ?>>The Skulls 2000</option>
<option value="Kangaroo Jack 2003" <?php selected(@$movie, 12) ?>>Kangaroo Jack 2003</option>
<option value="The Butterfly Effect 2004" <?php selected(@$movie, 13) ?>>The Butterfly Effect 2004</option>
<option value="Starsky and Hutch 2004" <?php selected(@$movie, 14) ?>>Starsky and Hutch 2004</option>
<option value="Slumdog Millionaire 2008" <?php selected(@$movie, 15) ?>>Slumdog Millionaire 2008</option>
<option value="Inception 2010" <?php selected(@$movie, 16) ?>>Inception 2010</option>
<option value="The Hunger Games 2012" <?php selected(@$movie, 17) ?>>The Hunger Games 2012</option>
<span class="error">* <?php echo $errormovie;?></span>
</select>
答案 0 :(得分:3)
如果这是您的实际代码,那么您已将span
元素放在<{em}里面的select
元素中,这当然是无稽之谈 - select
可以仅包含option
或optgroup
元素作为子级...因此,浏览器将忽略此位置的span
元素。
将放在select
元素的之外。
答案 1 :(得分:0)
你的代码片段没有太多内容,但如果我不得不猜测,我会说你错误地假设$ movie变量的值为“select”。尝试使用var_dump函数检查$ movie变量的内容。
答案 2 :(得分:0)
试试这个:
if ($_POST["movie"] == "select") {
$errormovie .= 'Please select a favourite movie';
}