youngtorise Posted June 4, 2012 Share Posted June 4, 2012 Hello, I am currently trying to take an html form with array entry, then store these array's into $_SESSION. Please help. The code is listed below. This is the form: <form method="post" action="system/processor/ac36e5fbdefed15a4daf3d7008723c87.php"> <p><table cellpadding=5 cellspacing=5 rules=none width="100%"> <tr> <th>Date</th> <th> </th> <th> </th> <th>Start Time</th> <th>End Time</th> </tr> <?php session_start(); $i = 1; while($i <= "$_SESSION[amt_dates]") { echo("<tr>"); echo("<td><select name=\"month[]\"> <option value=\"01\">January</option> <option value=\"02\">Febuary</option> <option value=\"03\">March</option> <option value=\"04\">April</option> <option value=\"05\">May</option> <option value=\"06\">June</option> <option value=\"07\">July</option> <option value=\"08\">August</option> <option value=\"09\">September</option> <option value=\"10\">October</option> <option value=\"11\">November</option> <option value=\"12\">December</option> </select></td>"); echo("<td><select name=\"day[]\">"); $h=1; while($h <= 31) { echo("<option value=\"$h\">$h</option>"); $h++; } echo("</select></td>"); echo("<td><select name=\"year[]\">"); $e= date(Y) + 10; $u = date(Y); while($u <= $e) { echo("<option value=\"$u\">$u</option>"); $u++; } echo("</select></td>"); echo("<td><select name=\"s_time[]\"> <option value=\"8\">8:00 AM</option> <option value=\"9\">9:00 AM</option> <option value=\"10\">10:00 AM</option> <option value=\"11\">11:00 AM</option> <option value=\"12\">12:00 PM</option> <option value=\"13\">1:00 PM</option> <option value=\"14\">2:00 PM</option> <option value=\"15\">3:00 PM</option> <option value=\"16\">4:00 PM</option> <option value=\"17\">5:00 PM</option> <option value=\"18\">6:00 PM</option> <option value=\"19\">7:00 PM</option> <option value=\"20\">8:00 PM</option> <option value=\"21\">9:00 PM</option></select></td>"); echo("<td><select name=\"e_time[]\"> <option value=\"8\">8:00 AM</option> <option value=\"9\">9:00 AM</option> <option value=\"10\">10:00 AM</option> <option value=\"11\">11:00 AM</option> <option value=\"12\">12:00 PM</option> <option value=\"13\">1:00 PM</option> <option value=\"14\">2:00 PM</option> <option value=\"15\">3:00 PM</option> <option value=\"16\">4:00 PM</option> <option value=\"17\">5:00 PM</option> <option value=\"18\">6:00 PM</option> <option value=\"19\">7:00 PM</option> <option value=\"20\">8:00 PM</option> <option value=\"21\">9:00 PM</option></select></td>"); $i++; } ?> <tr> <td colspan="5"><center><input type="submit" value="Add Dates To Order"></center></td> </tr> </table> </form> ac36e5fbdefed15a4daf3d7008723c87.php: <?phpsession_start();require('sql.php');#$a = "$_SESSION[amt_dates]";#$i = 1;#while($i <= $a){#Month$_SESSION['month'][$i] = "$_POST[month][$i]";$i++;}#$i = 1;#while($i <= $a){#day$_SESSION['day'][$i] = "$_POST[day][$i]";$i++;}#$i = 1;#while($i <= $a){#year$_SESSION['year'][$i] = "$_POST[year][$i]";$i++;}#$i = 1;#while($i <= $a){#s_time$_SESSION['s_time'][$i] = "$_POST[s_time][$i]";$i++;}#$i = 1;#while($i <= $a){#e_time$_SESSION['e_time'][$i] = "$_POST[e_time][$i]";$i++;}##header("location: http://www.pickinpal.zxq.net/review.php");exit;?> review.php: <form method="post" action=""> <p><table cellpadding=5 cellspacing=5 rules=none width="100%"> <tr> <th>Date</th> <th> </th> <th> </th> <th>Start Time</th> <th>End Time</th> </tr> <?php session_start(); # $a = "$_SESSION[amt_dates]"; # $i = 0; # while($i <= $a) { # echo("<tr>"); echo("<td>" . $_SESSION[month]['$i'] . "</td>"); echo("<td>" . $_SESSION[day]['$i'] . "</td>"); echo("<td>" . $_SESSION[year]['$i'] . "</td>"); echo("<td>" . $_SESSION[s_time]['$i'] . "</td>"); echo("<td>" . $_SESSION[e_time]['$i'] . "</td>"); echo("</tr>"); $i++; } # ?> </table></p> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 4, 2012 Share Posted June 4, 2012 What problem are you having? One issue that you have too many quotes, you don't need to quote a variable name if you're just referring to that variable. You can remove the quotes around the $_POST and $_SESSION variables. In the last piece of code, expressions like this: $_SESSION[month]['$i'] should be like this: $_SESSION['month'][$i] 1 Link to comment Share on other sites More sharing options...
youngtorise Posted June 4, 2012 Author Share Posted June 4, 2012 Ok I have now fixed the quotes and now nothing shows up in the place of where the variables are as if they equal nothing? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 4, 2012 Share Posted June 4, 2012 Are you sure they aren't empty? You can check the entire session array with print_r: print_r($_SESSION); Link to comment Share on other sites More sharing options...
youngtorise Posted June 4, 2012 Author Share Posted June 4, 2012 Ok now the display just prints: Array[1] or Array[2] in all the places Link to comment Share on other sites More sharing options...
justsomeguy Posted June 4, 2012 Share Posted June 4, 2012 That's going to be the structure of the $_SESSION array. You should check it to make sure it contains the data you think. It won't just print "Array[1]", it's going to list the contents of it. You may need to use the browser to view the page source to see everything. If your code is working correctly then it would show something like this: Array ( [month] => Array ( [0] => 6 [1] => 10 ) [day] => Array ( ...etc )) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now