Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShane McC
3,005 PointsHow to validate a multiple drop down list in php?
Hi,
I'm trying to figure out a way to propertly validate a mulitple drop down list in php. My below syntax produces a 404 error when I press the "submit" button. What am I doing wrong?
Thanks
PHP Syntax
$month = $_POST['month'];
$day = $_POST['day'];
if(isset($month) && $month === '0'){
$birthdayNumberError = __('<span STYLE="font-size: x-medium; color: #000000">Birthday works, I think</span>' ,'language');
$error_message .= 'Enter a valid Month\n';
$hasError = true;
} else if (isset($day) && $day === '0' && isset($month) && $month === '0'){
$birthdayNumberError = __('<span STYLE="font-size: x-medium; color: #000000">Birthday works - Day, I think - Else Statement</span>' ,'language');
$error_message .= 'Enter a valid Month\n';
$hasError = true;
}
HTML Syntax
<div class="pro_fields">
<li>
<label for="birthday">
<?php _e('Birthday:','language');?>
</label>
<br/>
<select name="month" id="month" style="width:200px">
<option value="-1">--Select A Month--</option>
<option value="1" <?PHP if($month==1) echo "selected";?>>January</option>
<option value="2" <?PHP if($month==2) echo "selected";?>>February</option>
<option value="3" <?PHP if($month==3) echo "selected";?>>March</option>
<option value="4" <?PHP if($month==4) echo "selected";?>>April</option>
<option value="5" <?PHP if($month==5) echo "selected";?>>May</option>
<option value="6" <?PHP if($month==6) echo "selected";?>>June</option>
<option value="7" <?PHP if($month==7) echo "selected";?>>July</option>
<option value="8" <?PHP if($month==8) echo "selected";?>>August</option>
<option value="9" <?PHP if($month==9) echo "selected";?>>September</option>
<option value="10" <?PHP if($month==10) echo "selected";?>>October</option>
<option value="11" <?PHP if($month==11) echo "selected";?>>November</option>
<option value="12" <?PHP if($month==12) echo "selected";?>>December</option>
</select>
<select name="day" id="day">
<option value="-1">--Select A Day--</option>
<option value="1" <?PHP if($day==1) echo "selected";?>>1</option>
<option value="2" <?PHP if($day==2) echo "selected";?>>2</option>
<option value="3" <?PHP if($day==3) echo "selected";?>>3</option>
<option value="4" <?PHP if($day==4) echo "selected";?>>4</option>
<option value="5" <?PHP if($day==5) echo "selected";?>>5</option>
<option value="6" <?PHP if($day==6) echo "selected";?>>6</option>
<option value="7" <?PHP if($day==7) echo "selected";?>>7</option>
<option value="8" <?PHP if($day==8) echo "selected";?>>8</option>
<option value="9" <?PHP if($day==9) echo "selected";?>>9</option>
<option value="10" <?PHP if($day==10) echo "selected";?>>10</option>
<option value="11" <?PHP if($day==11) echo "selected";?>>11</option>
<option value="12" <?PHP if($day==12) echo "selected";?>>12</option>
<option value="13" <?PHP if($day==13) echo "selected";?>>13</option>
<option value="14" <?PHP if($day==14) echo "selected";?>>14</option>
<option value="15" <?PHP if($day==15) echo "selected";?>>15</option>
<option value="16" <?PHP if($day==16) echo "selected";?>>16</option>
<option value="17" <?PHP if($day==17) echo "selected";?>>17</option>
<option value="18" <?PHP if($day==18) echo "selected";?>>18</option>
<option value="19" <?PHP if($day==19) echo "selected";?>>19</option>
<option value="20" <?PHP if($day==20) echo "selected";?>>20</option>
<option value="21" <?PHP if($day==21) echo "selected";?>>21</option>
<option value="22" <?PHP if($day==22) echo "selected";?>>22</option>
<option value="23" <?PHP if($day==23) echo "selected";?>>23</option>
<option value="24" <?PHP if($day==24) echo "selected";?>>24</option>
<option value="25" <?PHP if($day==25) echo "selected";?>>25</option>
<option value="26" <?PHP if($day==26) echo "selected";?>>26</option>
<option value="27" <?PHP if($day==27) echo "selected";?>>27</option>
<option value="28" <?PHP if($day==28) echo "selected";?>>28</option>
<option value="29" <?PHP if($day==29) echo "selected";?>>29</option>
<option value="30" <?PHP if($day==30) echo "selected";?>>30</option>
<option value="31" <?PHP if($day==31) echo "selected";?>>31</option>
</select>
<?php if($birthdayNumberError != '0') { ?>
<span class="error">
<?=$birthdayNumberError;?>
</span>
<?php } ?>
</li>
</div>