matt.sisto Posted March 20, 2009 Share Posted March 20, 2009 I am trying to build registration form so that when an selects a leap year and february, the day options will be restricted to 29, when they select a normal year and february the day options will be 28, and when April, June, September and november are selected the day options are 30, if any other month is selected the day option would be 31. I have made an attempt at the script however it is not working yet, does anyone know what is wrong with my script? I am relatively new to PHP so at the moment it is just trial and error, sorry if my code is a bit shoddy. !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Add Event</title> </head> <body> <legend> Date of birth Details <form method="post" action="addbirthdate.php"> <p><strong>Birth Date:</strong><br/> <select name="yearOptions" value="<?=$row['y']?>"> <?php $yearOptions = array ("0" => "[select]", "1" => "1950", "2" => "1951", "3" => "1952", "4" => "1953", "5" => "1954", "6" => "1955", "7" => "1956", "8" => "1957", "9" => "1958", "10" => "1959", "11" => "1960", "12" => "1961", "13" => "1962", "14" => "1963", "15" => "1964", "16" => "1965", "17" => "1966", "18" => "1967", "19" => "1968", "20" => "1969", "21" => "1970", "22" => "1971", "23" => "1972", "24" => "1973", "25" => "1974", "26" => "1975", "27" => "1976", "28" => "1977", "29" => "1978", "30" => "1979", "31" => "1980", "32" => "1981", "33" => "1982", "34" => "1983", "35" => "1984", "36" => "1985", "37" => "1986", "38" => "1987", "39" => "1988", "40" => "1989"); for ($x= 2009; $x<=2012; $x++) { echo "<option"; if ($x == $yearOptions) { echo " selected"; } echo ">$x</option>"; } ?> </select> <select name="monthOptions" value="<?=$row['m']?>"/> <?php $monthOptions = array ("0" => "[select]", "1" => "January", "2" => "February", "3" => "March", "4" => "April", "5" => "May", "6" => "June", "7" => "July", "8" => "August", "9" => "September", "10" => "October", "11" => "November", "12" => "December"); for ($x=1; $x <= count($monthOptions); $x++) { echo"<option value=\"$x\""; if ($x == $monthOptions) { echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select name="Day" value="<?=$row['d']?>"> <?php if ($yearOptions == "3","7","11","15","19","23","27","31","35","39"; && $monthOptions == "2") { $dayOptions = array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29"); } elseif ($monthOptions == "2") { $dayOptions = array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"); } elseif ($monthOptions == "4","6","9","11") { $dayOptions = array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30"); } else { $dayOptions = array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"); } for ($x=1; $x <= count($dayOptions); $x++) { echo "<option"; if ($x == $dayOptions) { echo " selected"; } echo ">$x</option>"; } ?> </select> <p><input type ="submit" value="confirm"/></p> </legend> </form> </body> </html> Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/150304-registration-form-dob-selection/ Share on other sites More sharing options...
BloodyMind Posted March 20, 2009 Share Posted March 20, 2009 well first of all this line $x needs to be concatenated : echo ">$x</option>"; should be echo ">" . $x . "</option>"; if ($x == $yearOptions) and other condition statements you are comparing an integer to an array which is always gonna give false you should use the $yearOptions[key] where key is the pointer key to ur array's current value I'd also recommend using foreach to loop around the array please tell me more about the error you receive Link to comment https://forums.phpfreaks.com/topic/150304-registration-form-dob-selection/#findComment-789436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.