Jump to content

Can't get chosen $variables <select> tags by user to display on results page (whilst using 'for' and 'foreach' loops)


zaniac

Recommended Posts

Below is a calendar I have setup. Here I've used the 'for' loop with the $day variable and the 'foreach' loop with the $month/$year variables. I did originally have this setup as a simple function, but thought originally it was this that which could have been causing the problem.(calendar.php)---------------------------------------------------------------------------------------------------<form action="resultsform.php" method="post">$year = range (2007, 2010);$month = array ('January' => 'January', 'February' => 'February', 'March'=>'March', 'April' => 'April', 'May'=>'May', 'June'=>'June', 'July'=>'July', 'August'=>'August', 'September'=>'September', 'October'=>'October', 'November' =>'November', 'December'=>'December');$day = range (1,31);echo '<select name="day">'; for ($day = 1; $day <=31; $day++) { echo"\n<option value=\"day\">$day</option>"; }echo"</select>";echo'<select name="month">'; foreach($month as $value) { echo"\n<option value=\"month\">$value</option>"; }echo '</select>';echo '<select name="year">'; foreach($year as $value) { echo"\n<option value=\"year\">$value</option>"; }echo '</select>';</form>---------------------------------------------------------------------------------------------------I can get the calendar to display on the form page. However I cannot get what has been selected on the the calendar to then display on the resultsform.php page. I've tried something like the following below to get the results to display, but it does not work(resultsform.php)--------------------------------------------------------------------------------------------------$birthdate = "$day $month $year";echo $birthdate;---------------------------------------------------------------------------------------------------I think I'm missing a rule perhaps in the calendar, but I've made other <select> tags in forms display on another page with no problem. Although these did not involve using 'for' and 'foreach' loops. Has anyone got any ideas on how to solve what is probably something fairly easy (lol)?Any advice ideas are greatly appreciated :)

Link to comment
Share on other sites

Add the $ at the beginning of the month, day, year values like this.echo"\n<option value=\"$year\">$value</option>";
Hmmm, I've given it a try, but no joy.I made a slight adjustment to the calendar in the $month array and added ....(' '=>'Month', 'January' => 'January'.....).. and then added the following if statement into my resultsform.php page... if ($month == ' '){ $problem = TRUE; echo'<p>No Month has been entered.</p>'; }Having done this, I've found through testing, the $month result is not being sent.
Link to comment
Share on other sites

I'm an idiot haha. Thanks for your help mma_fighter123 on this one, I have resolved the issue now. You were right, but I also made another error in a section I didn't think was relevent. Sorry for the time, but thanks again mate :)

Link to comment
Share on other sites

First off, this is really unneccessary:$month = array ('January' => 'January', 'February' => 'February', 'March'=>'March', 'April' => 'April', 'May'=>'May', 'June'=>'June', 'July'=>'July', 'August'=>'August', 'September'=>'September', 'October'=>'October', 'November' =>'November', 'December'=>'December');You can just do this:$month = array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');You don't gain anything by having the same values for the key and the value, it doesn't add anything.And this line:echo"\n<option value=\"day\">$day</option>";should be this:echo"\n<option value=\"$day\">$day</option>";This line:echo"\n<option value=\"month\">$value</option>";should be this:echo"\n<option value=\"$value\">$value</option>";And this line:echo"\n<option value=\"year\">$value</option>";should be this:echo"\n<option value=\"$value\">$value</option>";Also, you don't need this line at all:$day = range (1,31);

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...