如果ComboBox選擇弓箭手瀏覽器會呼應正確的,但如果ComboBox不會選擇弓箭手瀏覽器將回聲,我想知道如果我的語法是錯誤的。組合框在HTML和PHP
Wrong. Error: Undefined index text_hname.
這裏的結構:
<form action="server.php" method="POST">
<img src="images/logo.png" class="logo">
<div class="container">
<h1>Account Details</h1>
<br>
<label class="username">Username</label>
<input type="text" name="text_username" class="text_user" placeholder="Enter username">
<label class="password">Password</label>
<input type="text" name="text_password" class="text_pass" placeholder="Enter password">
<label class="email">Email</label>
<input type="text" name="text_email" class="text_email" placeholder="Enter email">
<label class="cname">Character Name</label>
<input type="text" name="text_cname" class="text_cname" placeholder="Enter Character Name">
<label class="character">Select Character</label>
<select class="names" name="text_hname">
<option>Archer</option>
<option>Barbarian</option>
<option>Balloon</option>
<option>Witch</option>
<option>Spirit</option>
<option>Hog Rider</option>
<option>Minion</option>
</select>
<img src="images/">
<br>
<input type="submit" class="submit" name="submit">
</div>
</form>
//option
$hero = $_POST['text_hname'];
if (isset($_POST['text_hname'])) {
if ($hero == 'Archers') {
echo "Correct";
} else {
echo "wrong";
}
}
這裏有問題嗎? – j08691
在你知道它是否存在之前,看起來你正在引用該數組鍵。參見[「Notice:Undefined index」](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef)。你也可以包含你的HTML代碼。 – showdev
您是否通過POST將參數text_hname發送到此文件? –