我使用两个简单的单选按钮并尝试传递值,然后使用$ _POST变量读取值,但设置的值为空
<form style="text-align:left;margin-left:80px;" class="form-inline signup" role="form" method="post" action="userdet.php">
<div class="form-group" style="padding-bottom:7px;">
<input type="text" name="first" class="form-control" placeholder="First Name" />
<input type="text" name="last" class="form-control" placeholder="Last Name" />
</div>
<div class="form-group" style="padding-bottom:7px;">
<input type="email" name="email" class="form-control" placeholder="Your Email" />
</div>
<div class="form-group" style="padding-bottom:7px;">
<input type="email" name="re-email" class="form-control" placeholder="Re-enter Email" />
</div>
<div class="form-group" style="padding-bottom:7px;">
<input type="password" name="password" class="form-control" placeholder="New Password" />
</div>
<span class="help-block">Birthday</span>
<div class="form-group" style="padding-bottom:7px;">
<select name="day" class="form-control" style="width:100px">
<?php
for($i=1;$i<=31;$i++)
{
echo '<option value='.$i.'>'.$i.'</option>';
}
?>
</select>
<select name="month" class="form-control">
<option value="January">January</option>
<option value="February">February</option>
<option value="Mars">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="year" class="form-control" style="width:120px">
<?php
for($i=1980;$i<=2015;$i++)
{
echo '<option value='.$i.'>'.$i.'</option>';
}
?>
</select>
</div>
<div class="form-group" style="padding-bottom:7px;">
<label class="radio inline" ><input type="radio" style="visibility:hidden;margin-left:-70px" value="not specified" name="gender" checked/></label>
<label class="radio inline" ><input type="radio" value="female" name="gender" />Female</label>
<label class="radio inline"><input type="radio" value="male" name="gender" />Male</label>
</div>
<div class="form-group" style="margin-top:12px;">
<button type="submit" class="btn btn-primary" name="submit">Sign Up</button>
</div>
</form>
$_POST['gender']
变量已设置,但即使检查了无线电也具有空值。所有其他后置变量都正常工作。
在php代码中,我只是一个接一个地使用echo打印值。
此代码可能有什么问题?
答案 0 :(得分:0)
尝试将名称改为'gender []',这将使用数组.. 然后在变量中捕获它,例如:$ gender = $ _POST ['gender']; 然后回应你可以使用的值:
if(is_array($gender)){
foreach ($gen as $gender){
echo $gender."<br />";
}
}
它对我有用!
答案 1 :(得分:-2)
尝试更改
<button type="submit" class="btn btn-primary" name="submit">Sign Up</button>
到
<input type="submit" class="btn btn-primary" name="submit" value="Sign Up">