nishmgopal Posted March 17, 2009 Share Posted March 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/ Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786882 Share on other sites More sharing options...
WolfRage Posted March 17, 2009 Share Posted March 17, 2009 Place this at the begining of your script. <?php session_start(); ?> Read here: http://us3.php.net/manual/en/function.session-start.php & here: http://us3.php.net/manual/en/intro.session.php Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786884 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 Insert Quote Place this at the begining of your script. Code: [select]<?php session_start(); ?>Read here: http://us3.php.net/manual/en/function.session-start.php & here: http://us3.php.net/manual/en/intro.session.php He already said he had that. Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786895 Share on other sites More sharing options...
nishmgopal Posted March 17, 2009 Author Share Posted March 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786898 Share on other sites More sharing options...
WolfRage Posted March 17, 2009 Share Posted March 17, 2009 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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786909 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786910 Share on other sites More sharing options...
iarp Posted March 17, 2009 Share Posted March 17, 2009 <?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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786914 Share on other sites More sharing options...
nishmgopal Posted March 17, 2009 Author Share Posted March 17, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786929 Share on other sites More sharing options...
iarp Posted March 17, 2009 Share Posted March 17, 2009 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."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786934 Share on other sites More sharing options...
WolfRage Posted March 17, 2009 Share Posted March 17, 2009 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.... Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786937 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786939 Share on other sites More sharing options...
nishmgopal Posted March 17, 2009 Author Share Posted March 17, 2009 thank you guys, i will try this and report bak Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786943 Share on other sites More sharing options...
jhlove Posted March 17, 2009 Share Posted March 17, 2009 i think need session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786968 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 jhlove please dont post if you haven't read the posts. it clearly states in 3 places of this topic that he has session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/149846-session-help-neededplease/#findComment-786978 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.