Moron Posted November 30, 2006 Share Posted November 30, 2006 Short and sweet. I have the following at the top of both my pages:[code]<?phpsession_start();$_SESSION['empcode'] = $empcode;$_SESSION['middle'] = $middle;$_SESSION['firstname'] = $firstname;$_SESSION['lastname'] = $lastname;$_SESSION['leavehours'] = $leavehours;$_SESSION['password'] = $password;?>[/code]On the second page, it has copied-and-pasted code in the query:[code]WHERE M2.[EMPNO] = '".$_POST['employeenumber']."' and M2.[MSSNO] = '".$_POST['password']."' [/code]I need the query to use the passed variables of..[code]$_SESSION['empcode'] = $empcode;$_SESSION['password'] = $password;[/code]What's the proper syntax? Quote Link to comment Share on other sites More sharing options...
komquat Posted November 30, 2006 Share Posted November 30, 2006 WHERE M2.[EMPNO] = '".$_SESSION['empcode']."' and M2.[MSSNO] = '".$_SESSION['password']."' And you only need those vairable on the first page of the session. You do not need to repeat the variables on every page. Quote Link to comment Share on other sites More sharing options...
Moron Posted November 30, 2006 Author Share Posted November 30, 2006 [quote author=komquat link=topic=116844.msg476364#msg476364 date=1164906570]WHERE M2.[EMPNO] = '".$_SESSION['empcode']."' and M2.[MSSNO] = '".$_SESSION['password']."' And you only need those vairable on the first page of the session. You do not need to repeat the variables on every page.[/quote]That's what I thought, but it crashes the entire query. Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted November 30, 2006 Share Posted November 30, 2006 Make sure you use "session_start()" at the top of the second page as well. Otherwise, the session variables won't be passed. Quote Link to comment Share on other sites More sharing options...
sploit Posted November 30, 2006 Share Posted November 30, 2006 what does it say - i mean the query error? did you try printing the query to see if it comes out ok? Quote Link to comment Share on other sites More sharing options...
Moron Posted November 30, 2006 Author Share Posted November 30, 2006 [quote author=sploit link=topic=116844.msg476391#msg476391 date=1164910373]what does it say - i mean the query error? did you try printing the query to see if it comes out ok?[/quote]My query is:[code]$RESULTDS=mssql_query("SELECT DISTINCT LH.[Employee Number], M2.[HRYRAT], M2.[EMPNO], M2.[MANLAP], M2.[PAYCTR], M2.[MANLAC], M2.[MANLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[NAMEMI], M2.[NAMEL], M2.[NAMEF], EH.[DATE], EH.[ENETPA], LH.[LOCC], EH.[EGRSER], EH.[EREGHR], EH.[EDEDUC], EH.[EROTHR], EH.[EFWHD], EH.[EPEDAT], EH.[ESSDED], EH.[EHOSPD], EH.[ELIFED], EH.[ECRUD], M2.[POSITN], M2.[MCTDWH], M2.[MHDATE], M2.[MCTDCS], M2.[MO3TOT], M2.[MCTDLD], M2.[MCTDGE], M2.[MALPPP], M2.[MSLPPP], M2.[MWHSTA], M2.[MWHALL], M2.[MWHADD], EH.[EGARND], EP.[EMPNO], DP.[EMPNO], EI.[DDEPTN], EI.[NEWOCC], EI.[HRYRAT], EI.[MEMPAD], EI.[MEMPCS], EI.[MEMPZI]FROM LEAVHST LH JOIN MASTERL2 M2 ON LH.[Employee Number]=M2.EMPNO JOIN EARNHIST EHON EH.[EEMPNO]=M2.EMPNO JOIN EMPPICTURE EPON EP.[EMPNO]=EH.EEMPNO JOIN Departments DPON DP.[EMPNO]=EP.EMPNO JOIN View_EmployeeInfo EION EI.[EMPNO]=M2.EMPNOWHERE M2.[EMPNO] = '".$_SESSION['empcode']."' and M2.[MSSNO] = '".$_SESSION['password']."' //WHERE M2.[EMPNO] = '".$_POST['employeenumber']."' and //M2.[MSSNO] = '".$_POST['password']."' ORDER BY EH.[DATE] desc"); $RESULT=mssql_fetch_assoc($RESULTDS) or die("<CENTER><img src=\"http://orserva/images/invalidnumber.gif\"></CENTER><BR><CENTER><table width=60 //border=0><tr><td><font size=\"3\" color=\"#000000\" face=\"arial\">Need help? Here is an example entry:</font></td></tr><tr><td align=center><img //src=\"http://orserva/images/leaveexample.gif\"></td></tr><tr><td><font size=\"3\" color=\"#000000\" //face=\"arial\">Enter your Employee Number<BR>Enter your password (Social Security Number)<BR>Click Submit<BR><BR>If you're still having difficulty, click here to </font><font size=\"3\" color=\"#ff0000\" //face=\"arial\"><BR><a href=\"mailto:HelpDesk@cortn.org? subject=Problem with the Employee Information //System\"><b>E-mail the HelpDesk</b></a></font></td></tr></table></CENTER>");[/code](My original WHERE statement is commented out)At the top of the page, I have:[code]<?phpsession_start();$_SESSION['empcode'] = $empcode;$_SESSION['middle'] = $middle;$_SESSION['firstname'] = $firstname;$_SESSION['lastname'] = $lastname;$_SESSION['leavehours'] = $leavehours;$_SESSION['password'] = $password;?>[/code] Quote Link to comment Share on other sites More sharing options...
komquat Posted November 30, 2006 Share Posted November 30, 2006 Did you delcare the session variable on a different page, the page where the session starts? If you did, then you may be reseting them to something different by declaring them on every page. Try deleting [code=php:0]$_SESSION['empcode'] = $empcode;$_SESSION['middle'] = $middle;$_SESSION['firstname'] = $firstname;$_SESSION['lastname'] = $lastname;$_SESSION['leavehours'] = $leavehours;$_SESSION['password'] = $password;[/code]and only leaving[code=php:0]session_start();[/code] Quote Link to comment Share on other sites More sharing options...
Moron Posted December 1, 2006 Author Share Posted December 1, 2006 I tried all of the above. Rather than commenting out my original WHERE statement, I removed it and I no longer get the SQL errors. But....it still isn't passing on the "empcode" and "password" variables to the second form. Quote Link to comment Share on other sites More sharing options...
komquat Posted December 1, 2006 Share Posted December 1, 2006 Why don't you post the page that include the sql and the page where the session starts, then we can see what is going on Quote Link to comment Share on other sites More sharing options...
Moron Posted December 1, 2006 Author Share Posted December 1, 2006 [quote author=komquat link=topic=116844.msg476986#msg476986 date=1164983365]Why don't you post the page that include the sql and the page where the session starts, then we can see what is going on[/quote]It won't let me post the entire thing because it's too many characters. The first thing on my page is:[code]<?phpsession_start();$_SESSION['empcode'] = $empcode;$_SESSION['middle'] = $middle;$_SESSION['firstname'] = $firstname;$_SESSION['lastname'] = $lastname;$_SESSION['leavehours'] = $leavehours;$_SESSION['password'] = $password;?>[/code]The query is:[code]$RESULTDS=mssql_query("SELECT DISTINCT LH.[Employee Number], M2.[HRYRAT], M2.[EMPNO], M2.[MANLAP], M2.[PAYCTR], M2.[MANLAC], M2.[MANLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[NAMEMI], M2.[NAMEL], M2.[NAMEF], EH.[DATE], EH.[ENETPA], LH.[LOCC], EH.[EGRSER], EH.[EREGHR], EH.[EDEDUC], EH.[EROTHR], EH.[EFWHD], EH.[EPEDAT], EH.[ESSDED], EH.[EHOSPD], EH.[ELIFED], EH.[ECRUD], M2.[POSITN], M2.[MCTDWH], M2.[MHDATE], M2.[MCTDCS], M2.[MO3TOT], M2.[MCTDLD], M2.[MCTDGE], M2.[MALPPP], M2.[MSLPPP], M2.[MWHSTA], M2.[MWHALL], M2.[MWHADD], EH.[EGARND], EP.[EMPNO], DP.[EMPNO], EI.[DDEPTN], EI.[NEWOCC], EI.[HRYRAT], EI.[MEMPAD], EI.[MEMPCS], EI.[MEMPZI]FROM LEAVHST LH JOIN MASTERL2 M2 ON LH.[Employee Number]=M2.EMPNO JOIN EARNHIST EHON EH.[EEMPNO]=M2.EMPNO JOIN EMPPICTURE EPON EP.[EMPNO]=EH.EEMPNO JOIN Departments DPON DP.[EMPNO]=EP.EMPNO JOIN View_EmployeeInfo EION EI.[EMPNO]=M2.EMPNOWHERE M2.[EMPNO] = '".$_SESSION['empcode']."' and M2.[MSSNO] = '".$_SESSION['password']."'ORDER BY EH.[DATE] desc"); $RESULT=mssql_fetch_assoc($RESULTDS) or die("<CENTER><img src=\"http://orserva/images/invalidnumber.gif\"></CENTER><BR><CENTER><table width=60 //border=0><tr><td><font size=\"3\" color=\"#000000\" face=\"arial\">Need help? Here is an example entry:</font></td></tr><tr><td align=center><img //src=\"http://orserva/images/leaveexample.gif\"></td></tr><tr><td><font size=\"3\" color=\"#000000\" //face=\"arial\">Enter your Employee Number<BR>Enter your password (Social Security Number)<BR>Click Submit<BR><BR>If you're still having difficulty, click here to </font><font size=\"3\" color=\"#ff0000\" //face=\"arial\"><BR><a href=\"mailto:HelpDesk@cortn.org? subject=Problem with the Employee Information //System\"><b>E-mail the HelpDesk</b></a></font></td></tr></table></CENTER>");[/code]Please note that this page works like a charm if I put an input form on the page that calls it and I enter my employee number and password again. I just can't seem to keep it in a session and just pass it on. Quote Link to comment Share on other sites More sharing options...
komquat Posted December 1, 2006 Share Posted December 1, 2006 It needs to fill the SESSION variables with values, so you will need the values inputted into the variable somehow, where that is the previous form, or through the DB. How is this page being used? When you declare the variables at the top, you are assigning blank values, so it will not work, you need these variables assigned. Quote Link to comment Share on other sites More sharing options...
keeB Posted December 1, 2006 Share Posted December 1, 2006 Basically your problem is you're setting the variables to null on the second page.Think of it this way:page1: [code=php:0]session_start(); $_SESSION['keeb'] = "wow!";[/code]page2:[code=php:0]session_start();echo $_SESSION['keeb'][/code] Quote Link to comment Share on other sites More sharing options...
Moron Posted December 1, 2006 Author Share Posted December 1, 2006 On the input page, here is the snippet from my table:[code]<tr> <td align=right> <form action="employeeinformationmenu.php" name="leave" method="post" onSubmit="return validateForm(leave);"> <font size="2" color="#000000" face="arial"><NOBR>Employee Number:  </NOBR></font> </td> <td align=left><input name="employeenumber" type="text" onSubmit="return validateForm(leave);"/><BR> </td> </tr> <tr> <td align=right> <font size="2" color="#000000" face="arial"><NOBR>Password:  </NOBR></font></td><td align=left><input name="password" type="password" / onSubmit="return validateForm(leave);"></td></tr><tr><td align=center colspan=2><BR> <input type="submit"/ value="Submit"> </form> </td> </tr>[/code]On the page this hits, my query contains:[code]WHERE M2.[EMPNO] = '".$_POST['employeenumber']."' and M2.[MSSNO] = '".$_POST['password']."' [/code]This second page works fine. So....1. They enter their Employee Number ("empcode") and password ("password").2. Page 2 brings up their basic info with a menu. One menu item is paystubs. This second (menu) page works great.3. When I click Paystubs, I get no SQL errors, but the query dies ands says "invalid username or password" (this is what I specified for it to say). So empcode and password aren't being passed on to paystubresults.php. Quote Link to comment Share on other sites More sharing options...
Moron Posted December 1, 2006 Author Share Posted December 1, 2006 [quote author=keeB link=topic=116844.msg477037#msg477037 date=1164989137]Basically your problem is you're setting the variables to null on the second page.Think of it this way:page1: [code=php:0]session_start(); $_SESSION['keeb'] = "wow!";[/code]page2:[code=php:0]session_start();echo $_SESSION['keeb'][/code][/quote]I tried echoing [b]empcode[/b] and [b]password[/b] on the second page and it gave me nothing. It's like those variables aren't being passed. Quote Link to comment Share on other sites More sharing options...
komquat Posted December 1, 2006 Share Posted December 1, 2006 The page after the form, try this:[code=php:0]<?session_start();$_SESSION['empcode'] = $_POST['employeenumber'];$_SESSION['middle'] = $_POST['middle'];$_SESSION['firstname'] = $_POST['firstname'];$_SESSION['lastname'] = $_POST['lastname'];$_SESSION['leavehours'] = $l_POST['eavehours'];$_SESSION['password'] = $_POST['password'];?>[/code]Do not include $_SESSION['empcode'] = $_POST['empcode'];$_SESSION['middle'] = $_POST['middle'];$_SESSION['firstname'] = $_POST['firstname'];$_SESSION['lastname'] = $_POST['lastname'];$_SESSION['leavehours'] = $l_POST['eavehours'];$_SESSION['password'] = $_POST['password'];On anyother pages, you should then be able to recall all this data! Quote Link to comment Share on other sites More sharing options...
Moron Posted December 1, 2006 Author Share Posted December 1, 2006 [quote author=komquat link=topic=116844.msg477090#msg477090 date=1164993127]The page after the form, try this:[code=php:0]<?session_start();$_SESSION['empcode'] = $_POST['employeenumber'];$_SESSION['middle'] = $_POST['middle'];$_SESSION['firstname'] = $_POST['firstname'];$_SESSION['lastname'] = $_POST['lastname'];$_SESSION['leavehours'] = $l_POST['eavehours'];$_SESSION['password'] = $_POST['password'];?>[/code]Do not include $_SESSION['empcode'] = $_POST['empcode'];$_SESSION['middle'] = $_POST['middle'];$_SESSION['firstname'] = $_POST['firstname'];$_SESSION['lastname'] = $_POST['lastname'];$_SESSION['leavehours'] = $l_POST['eavehours'];$_SESSION['password'] = $_POST['password'];On anyother pages, you should then be able to recall all this data![/quote]Thanks, but it didn't work. There are no SQL errors, but it tells me again that my employee number or password is invalid. I was using these parameters on the previous page, but they aren't being passed on. Quote Link to comment 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.