stackumhi Posted September 15, 2009 Share Posted September 15, 2009 Got a session question this time. Page 1 - I am choosing a date with a "date picker" and entering the values of the start date and end date into a session - works fine Page 2 - Pulling those values from session and using them as data to enter into a mysql DB - again, works fine After the sql insert script runs (works fine) it then calls header ('Location: payroll-list-contractors.php'); and sends user back to page 1 again to choose another contractor from the list and start the process over... But, the session value of my dates do not follow for some reason after the header is called. Both scripts are in the same directory / domain / etc... I have found a lot on this subject but nothing I have tried seems to work, including: putting .SID after the header session_write_close(); before the header call Thank you for any help. Page 1 code - - <?php session_start(); include '../admin/includes/authorize.php'; include '../admin/includes/dbconnect.php'; $_SESSION['payroll_start_date'] = $_REQUEST["start_date"]; $_SESSION['payroll_end_date'] = $_REQUEST["end_date"]; $payroll_start_date = $_SESSION['payroll_start_date']; $payroll_end_date = $_SESSION['payroll_end_date']; ?> Page 2 code - - <?php session_start(); //ini_set('display_errors', 1); //error_reporting(E_ALL|E_STRICT); include '../admin/includes/authorize.php'; include '../admin/includes/dbconnect.php'; $client_id = $_SESSION['client_id']; $payroll_start_date = $_SESSION['payroll_start_date']; $payroll_end_date = $_SESSION['payroll_end_date']; $contractor_id = $_GET["contractor_id"]; $result = mysql_query("SELECT first_name, last_name FROM CONTRACTORS WHERE contractor_id = '$contractor_id'"); $row = mysql_fetch_array($result) or die(mysql_error()); $first_name = $row['first_name']; $last_name = $row['last_name']; if(isset($_POST['submit'])) { $query = "INSERT INTO PAYROLL SET `client_id` = '".$_SESSION['client_id']."',`contractor_id` = '".$_GET["contractor_id"]."' ,`payroll_start_date` = '".$_GET["payroll_start_date"]."' ,`payroll_end_date` = '".$_GET["payroll_end_date"]."' ,`hours_worked` = '".$_POST['hours_worked']."', `hourly_rate` = '".$_POST['hourly_rate']."', `deductions` = '".$_POST['deductions']."',`advance` = '".$_POST['advance']."',`comments` = '".$_POST['comments']."',`date_entered` = NOW()"; mysql_query($query) or die(mysql_error()); session_write_close(); header('Location: payroll-list-contractors.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/ Share on other sites More sharing options...
mikesta707 Posted September 15, 2009 Share Posted September 15, 2009 do a print_r on the session variable before the header and on the next page, and see what output you get Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919100 Share on other sites More sharing options...
stackumhi Posted September 15, 2009 Author Share Posted September 15, 2009 I checked it with print_r($_SESSION); and did see 2 other vaules in there (that should be) but my dates were not there which is very starnge because they are used on the same page in some code below: Am I assigning them wrong? $_SESSION['payroll_start_date'] = $_REQUEST["start_date"]; $_SESSION['payroll_end_date'] = $_REQUEST["end_date"]; $payroll_start_date = $_SESSION['payroll_start_date']; $payroll_end_date = $_SESSION['payroll_end_date']; code that uses the values from session---- echo "<a href='enter-payroll-hourly.php?payroll_start_date=$payroll_start_date&payroll_end_date=$payroll_end_date&contractor_id=". $row['contractor_id']. "'/>". $row['first_name']. " ". $row['last_name'] ; echo "<br/><br/>"; Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919106 Share on other sites More sharing options...
mikesta707 Posted September 15, 2009 Share Posted September 15, 2009 not unless you aren't passing your variables right. try a print_r on the $_REQUEST variable and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919110 Share on other sites More sharing options...
stackumhi Posted September 15, 2009 Author Share Posted September 15, 2009 Just tried this - - echo sprintf("<pre>%s</pre>", print_r($_SESSION, true)); And got the following on both pages Array ( [username] => name@website.com [client_id] => 104 [payroll_start_date] => 2009-09-10 [payroll_end_date] => 2009-09-10 ) Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919115 Share on other sites More sharing options...
mikesta707 Posted September 15, 2009 Share Posted September 15, 2009 ok well you set the variables correctly it seems. do you have session start on the top of the second page? the one that is payrool-list-contractors.php or something like that Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919120 Share on other sites More sharing options...
stackumhi Posted September 15, 2009 Author Share Posted September 15, 2009 Here is the result for the print_r($_REQUEST); -- - - - Array ( [phpSESSID] => d1856tlghbllf7eb3gnrtusql1 ) Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919122 Share on other sites More sharing options...
stackumhi Posted September 15, 2009 Author Share Posted September 15, 2009 Yes....session_start(); on top of every page. Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919123 Share on other sites More sharing options...
mikesta707 Posted September 15, 2009 Share Posted September 15, 2009 ahh ok, then it seems that you aren't passing the request variables correctly. can I see the code that is supposed to pass the request data to the page that sets the session variables Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919125 Share on other sites More sharing options...
stackumhi Posted September 15, 2009 Author Share Posted September 15, 2009 Sure, it is the same page (page 1) <?php session_start(); include '../admin/includes/authorize.php'; include '../admin/includes/dbconnect.php'; $_SESSION['payroll_start_date'] = $_REQUEST["start_date"]; $_SESSION['payroll_end_date'] = $_REQUEST["end_date"]; $payroll_start_date = $_SESSION['payroll_start_date']; $payroll_end_date = $_SESSION['payroll_end_date']; ?> We just tried this instead of the above code: if( !isset($_SESSION['payroll_start_date'] ){ $_SESSION['payroll_start_date'] = $_REQUEST["start_date"]; } if( !isset($_SESSION['payroll_end_date'] ){ $_SESSION['payroll_end_date'] = $_REQUEST["end_date"]; } But are getting a parse error...looking for it now Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919148 Share on other sites More sharing options...
stackumhi Posted September 15, 2009 Author Share Posted September 15, 2009 Hi Mike, Thanks for your help. We got it working. Final code below: if( !isset($_SESSION['payroll_start_date']) ){ $_SESSION['payroll_start_date'] = $_REQUEST["start_date"]; } if( !isset($_SESSION['payroll_end_date']) ){ $_SESSION['payroll_end_date'] = $_REQUEST["end_date"]; } $payroll_start_date = $_SESSION['payroll_start_date']; $payroll_end_date = $_SESSION['payroll_end_date']; Quote Link to comment https://forums.phpfreaks.com/topic/174368-solved-losing-session-value-after-header-is-called/#findComment-919157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.