如果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发送到此文件? –