I have a dropdown box that holds the days 1-31 and i want to store/save what the user has previously selected if they return to the page.
My function to generate the box is:
public function fetchDDMMYYYYDropdown($select_d,$session_d) {
$days = range (1, 31);
$dropdown .= '<select name="'.$select_d.'">';
foreach($days as $key=>$name){
if($session_d==$name){
$session = 'selected';
}
$dropdown .= '<option value="'.sprintf("%02d", $name).'" selected="'.$session.'">'.sprintf("%02d", $name).'</option>';
}
$dropdown .= '</select>';
return $dropdown;
}
And my form is on this page:
<?php
session_start();
include("includes/func.class.php");
$dob = $func->fetchDDMMYYYYDropdown('dob_d', $_SESSION['dob_d']);
?>
<form action="t35t_send.php" method="get">
<?php echo $dob;?>
<input type="submit" value="send">
</form>
And it goes to this to save the SESSION variable:
session_start();
$_SESSION['dob_d'] = $_GET['dob_d'];
$dob = $_SESSION['dob_d'];
echo $dob;
I can tell that the $_SESSION['dob_d'] is correct and saved as i can output it inside both the function and the initial form page - so it's just the following which must not be right but at the moment the dropdown box just resets back to the first value, not the saved session:
if($session_d==$name){
$session = 'selected';
}
$dropdown .= '<option value="'.sprintf("%02d", $name).'" selected="'.$session.'">'.sprintf("%02d", $name).'</option>';