Monkuar Posted March 4, 2012 Share Posted March 4, 2012 Okay, this is my loop to show the birthday for Years. <?php for ($i=2006; $i>=1900; $i=$i-1) { echo "<option value='$i'>$i</option>"; } ?> It will show 2012 to 1900 as a dropdown menu.. in my select form. Now I want to check the user input against this loop. The form is: <select name="BirthDay[]"> <?php for ($i=2012; $i>=1900; $i=$i-1) { echo "<option value='$i'>$i</option>"; } ?> </select> Now, I want to use in_array function to check if it equals any of the values I looped, if it doesn't echo out "Hacker!" Here is my in_array $bday = array( NEED TO PUT THIS LOOP HERE SOMEHOW?!?! ); if (!in_array($_POST['BirthDay'], $bday)) { message("Please select a Correct Birthday, or u trying to hack"); } Thanks if u can help! Link to comment https://forums.phpfreaks.com/topic/258233-dynamically-check-in_array/ Share on other sites More sharing options...
marcbraulio Posted March 4, 2012 Share Posted March 4, 2012 for ($i=2012; $i>=1900; $i=$i--) { echo "<option value='$i'>$i</option>"; $bday[] = $i; } if (!in_array($_POST['BirthDay'], $bday)) { message("Please select a Correct Birthday, or u trying to hack"); } Couple of things... 1. Why not use "$i=$i--" instead of "$i=$i-1"? 2. Why would you want to dynamically make an array of something that you know for a fact is not going to change? Save yourself some resources and do a static array of the years instead of running it every single time. 3. I really hope that is not the kind of error messages you give your users. Link to comment https://forums.phpfreaks.com/topic/258233-dynamically-check-in_array/#findComment-1323703 Share on other sites More sharing options...
Monkuar Posted March 4, 2012 Author Share Posted March 4, 2012 for ($i=2012; $i>=1900; $i=$i--) { echo "<option value='$i'>$i</option>"; $bday[] = $i; } if (!in_array($_POST['BirthDay'], $bday)) { message("Please select a Correct Birthday, or u trying to hack"); } Couple of things... 1. Why not use "$i=$i--" instead of "$i=$i-1"? 2. Why would you want to dynamically make an array of something that you know for a fact is not going to change? Save yourself some resources and do a static array of the years instead of running it every single time. 3. I really hope that is not the kind of error messages you give your users. If I don't use $i=$i-1, and use the $i-- there is a 2nd delay lag when running the script Dunno why, but there is, I switched it back to $i=$i-1 and it's working fine. Thanks for your help Link to comment https://forums.phpfreaks.com/topic/258233-dynamically-check-in_array/#findComment-1323708 Share on other sites More sharing options...
marcbraulio Posted March 4, 2012 Share Posted March 4, 2012 No problem, best of luck! Link to comment https://forums.phpfreaks.com/topic/258233-dynamically-check-in_array/#findComment-1323709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.