What has already been said in regards to both selects holding the same name, still stands.
Sidenote: (I renamed the 2nd select to time2
)
However, in order to use the time from either radio button/dropdown selects, you need to use an isset
conditional statement, then use that variable for your DB insert.
Tested as follows while naming the submit button as my own self test and inside the same file. You can modify it to suit.
Scenario: The $time
variable that's being (set) then passed to your DB, will be set as such, depending on which time select was chosen.
<?php
if(isset($_POST['submit'])){
if(isset($_POST['time'])){
$time=$_POST['time'];
echo $time;
}
if(isset($_POST['time2'])){
$time=$_POST['time2'];
echo $time;
}
}
?>
<form name="list" action="" method="post">
<script>
function check(){
if(document.getElementById('1H').checked) {
document.getElementById('D1H').style.display = 'block';
document.getElementById('D2H').style.display = 'none';
}
else {
document.getElementById('D1H').style.display = 'none';
document.getElementById('D2H').style.display = 'block';
}}
</script>
Choose:
<input type="radio" onclick="javascript:check();" name="duration" id="1H">1 Hour
<input type="radio" onclick="javascript:check();" name="duration" id="2H">2 Hour
Choose time slot:
<div id="D1H" style="display:none">
<select name="time" >
<option value="">---Choose---</option>
<option value="8-9">8:00am-9:00am</option>
</select>
</div>
<div id="D2H" style="display:none">
<select name="time2" >
<option value="">---Choose---</option>
<option value="8-10">8:00am-10:00am</option>
</select>
</div>
<input type="submit" name="submit" value="Next">
EDIT (DB-related)
And in your case, it would be: (and do name your submit button to name="submit"
for this):
<?php
if(isset($_POST['submit'])){
if(isset($_POST['time'])){
$lab=$_POST['lab'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$time=$_POST['time'];
$results = mysql_query("SELECT COUNT(*) FROM `booking` WHERE `lab` = '".$lab."' AND `day` = '".$day."' AND `month` = '".$month."' AND `year` = '".$year."' AND `time` = '".$time."'");
}
if(isset($_POST['time2'])){
$lab=$_POST['lab'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$time=$_POST['time2'];
$results = mysql_query("SELECT COUNT(*) FROM `booking` WHERE `lab` = '".$lab."' AND `day` = '".$day."' AND `month` = '".$month."' AND `year` = '".$year."' AND `time` = '".$time."'");
}
}
?>