Jump to content

[SOLVED] Losing Session value after header is called


stackumhi

Recommended Posts

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');

}

?>

 

Link to comment
Share on other sites

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/>";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.