Jump to content

Session() help needed...please


nishmgopal

Recommended Posts

HI guys, I am assigning my session like this:

 

$sql="SELECT * FROM Job_ID WHERE Job_Name='$projectname'";
$result = mysql_query($sql) or die ("Couldn't execute query.");

while ($row=mysql_fetch_array($result))

$Job_ID=$row['Job_ID'];
{
if(isset($_POST['Job_ID']))
   {
    $_SESSION['Job_ID']=$Job_ID; 
	}
}
[code]

and at the top of this page I have session_start();.

On the other pages, where I want to use this job id variable I have got:

[code]
  <?php

session_start();
if(isset( $_SESSION['Job_ID']))
{
  $_SESSION['Job_ID']=$Job_ID;
}
echo $_SESSION['Job_ID'];

?>

 

But it doesnt echo anything and when I try to use the $_SESSION['Job_ID'] variable nothing is returned.  Can someone please help.

Link to comment
Share on other sites

I think it should be this:

 

$sql="SELECT * FROM Job_ID WHERE Job_Name='$projectname'";
$result = mysql_query($sql) or die ("Couldn't execute query.");

while ($row=mysql_fetch_array($result))
{

$Job_ID=$row['Job_ID'];

if(isset($_POST['Job_ID']))
   {
    $_SESSION['Job_ID']=$Job_ID; 
	}
}

 

You had the $Job_ID outside of the while loop.

Link to comment
Share on other sites

I think it should be this:

 

$sql="SELECT * FROM Job_ID WHERE Job_Name='$projectname'";
$result = mysql_query($sql) or die ("Couldn't execute query.");

while ($row=mysql_fetch_array($result))
{

$Job_ID=$row['Job_ID'];

if(isset($_POST['Job_ID']))
   {
    $_SESSION['Job_ID']=$Job_ID; 
	}
}

 

You had the $Job_ID outside of the while loop.

 

i tried this got and got nothing again...and yes i do have session_start at the start of each page

Link to comment
Share on other sites

On your second page you are reseting job id with a new null variable.

  <?php
session_start();
if(isset( $_SESSION['Job_ID']))
{
  $_SESSION['Job_ID']=$Job_ID; //Here is where you set your session var to a null variable.
}
echo $_SESSION['Job_ID'];
?>

Link to comment
Share on other sites

Wait a second. Do you have a table named Job_ID and a field named Job_ID? It looks like you are trying to one from a table and one from a field.

 

edit: wolfrage is correct too. sorry i didnt notice it was 2 pages since the code tags were messed up. it should be:

 

<?php
session_start();
if(!isset( $_SESSION['Job_ID']))
{
  $_SESSION['Job_ID']=$Job_ID; //Here is where you set your session var to a null variable.
}
echo $_SESSION['Job_ID'];
?>

Link to comment
Share on other sites

<?php
session_start();
$sql="SELECT * FROM Job_ID WHERE Job_Name='$projectname'"; # The table and column name the same? Job_ID?
$result = mysql_query($sql) or die ("Couldn't execute query.");

while ($row=mysql_fetch_array($result)) {
  $Job_ID = $row['Job_ID'];
  if(isset($_POST['Job_ID'])) {
        $_SESSION['Job_ID'] = $Job_ID; 
    }
}

 

Other page:

  <?php
session_start();

if(isset( $_SESSION['Job_ID']))
{
  $_SESSION['Job_ID'] = $Job_ID; # is $Job_ID set on this other page?
}
echo $_SESSION['Job_ID'];

?>

Link to comment
Share on other sites

That was my mistake, the table name should have been Job_Table

 

However i made the changes and still not getting anything.  This is the code now:

 

<?php 
session_start();

$sql="SELECT * FROM Job_Table WHERE Job_Name='$projectname'";
$result = mysql_query($sql) or die ("Couldn't execute query.");

while ($row=mysql_fetch_array($result)) {
  $Job_ID = $row['Job_ID'];
  if(isset($_POST['Job_ID'])) {
        $_SESSION['Job_ID'] = $Job_ID; 
    }
}

 

and the other page:

 

<?php


session_start();

if(isset( $_SESSION['Job_ID']))
{
  $_SESSION['Job_ID'];
}
echo $_SESSION['Job_ID'];

?>

 

still no luck on the echo

Link to comment
Share on other sites

Is $projectname set properly?

put echo $sql; just after the sql statement and post the result here

and whats the value of $_POST['Job_ID'] ?

 

<?php
$sql="SELECT * FROM Job_Table WHERE Job_Name='$projectname'";
echo $sql . "<br />";
echo $_POST['Job_ID'];
$result = mysql_query($sql) or die ("Couldn't execute query.");
?>

Link to comment
Share on other sites

Also why even have this

<?php
if(isset( $_SESSION['Job_ID']))
{
  $_SESSION['Job_ID'];
}
?>

or at least change it to something meaningful like:

<?php
if(isset($_SESSION['Job_ID']))
{
  echo $_SESSION['Job_ID'];
}
else { echo 'Job ID Not Set.';}
?>

echo echo echo ......

yeah I would try what iarp said to do but with the second page you posted the if statement there is not need because you arent actually doing anything with it.

nvm....

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.