Jump to content

Session help, please?


Moron

Recommended Posts

Short and sweet. I have the following at the top of both my pages:

[code]<?php
session_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?
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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 EH
ON EH.[EEMPNO]=M2.EMPNO JOIN EMPPICTURE EP
ON EP.[EMPNO]=EH.EEMPNO JOIN Departments DP
ON DP.[EMPNO]=EP.EMPNO JOIN View_EmployeeInfo EI
ON EI.[EMPNO]=M2.EMPNO

WHERE 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]<?php
session_start();
$_SESSION['empcode'] = $empcode;
$_SESSION['middle'] = $middle;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$_SESSION['leavehours'] = $leavehours;
$_SESSION['password'] = $password;
?>[/code]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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]<?php
session_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 EH
ON EH.[EEMPNO]=M2.EMPNO JOIN EMPPICTURE EP
ON EP.[EMPNO]=EH.EEMPNO JOIN Departments DP
ON DP.[EMPNO]=EP.EMPNO JOIN View_EmployeeInfo EI
ON EI.[EMPNO]=M2.EMPNO

WHERE 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.
Link to comment
Share on other sites

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. 
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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:&nbsp&nbsp;</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:&nbsp&nbsp;</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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

[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.
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.