我能够传递HTML表单中提供的所有表单值,但其中两个无法读取发布。
我可以阅读以下数据:
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$cell = $_POST['cell'];
$address = $_POST['address'];
$zip = $_POST['zip'];
$city = $_POST['city'];
$program = $_POST['program'];
这两个变量总是读取空值:
$location = $_POST['program2'];
$batch = $_POST['batch'];
这是我的HTML代码
<div class="form-group">
<select class="form-control" name="program" id="program" required>
<option readonly>Select Your Class</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
</div>
<div class="form-group">
<select class="form-control" name="program2" id="program2" required>
<option readonly>Select your Choice</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
<div class="form-group">
<select class="form-control" name="batch" id="batch" required>
<option readonly>Select Your Choice</option>
<option>1</option>
<option>21</option>`enter code here`
</select>
</div>
答案 0 :(得分:-1)
您应该为选项标记添加'value'属性。像这样:
<option value = "1">1</option>
答案 1 :(得分:-1)
您没有将值属性传递给选项列表。您的代码应如下所示:
<div class="form-group">
<select class="form-control" name="program" id="program" required>
<option value="" readonly>Select Your Class</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</div>
<div class="form-group">
<select class="form-control" name="program2" id="program2" required>
<option value="" readonly>Select your Choice</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div class="form-group">
<select class="form-control" name="batch" id="batch" required>
<option value="" readonly>Select Your Choice</option>
<option value="1">1</option>
<option value="21">21</option>`enter code here`
</select>
</div>
For more reference you could check the below links:
https://www.w3schools.com/tags/tag_select.asp
https://www.w3schools.com/tags/tag_option.asp