• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Login page problem?

I am making a login page but keep getting errors can someone look at my code and help please?
Here is the code from the "login.php" page.

<?php
$dbc = mssql_connect ('cacapppro01.cup.hp.com','nskinfo','webres');
$query = mssql_query("            SELECT      DISTINCT name FROM      staffList WHERE      Dept = '5996' ORDER BY name");
echo "<select name=\"STAFFNAME\">";
while( list($field1, $field2) = mssql_fetch_array($query) ){
echo "<option value = \"$field2\">$field1</option>\n";
}
echo "</select>";
mssql_close($dbc);
?></TD></TR>
                          <TR>
                            <TD class=smallfont>&nbsp;</TD>
                          </TR>
                          <TR>
                            <TD>&nbsp;</TD></TR>
                          <TR>
                            <TD class=EmailPasswordSize>Password:</TD></TR>
                          <TR>
                            <TD><INPUT style="WIDTH: 100%" maxLength=50  type="password" name="NSKPasswd"></TD></TR>
                          <TR>
                            <TD class=spacer></TD></TR>
                          <TR>
                            <TD align=right height=10></TD></TR>
                          <TR>
                            <TD align=right>
                              <DIV align=right>
<input type="hidden" name="hidden_sub" value="LOGGED">
<input type="hidden" name="STAFFDEPT" value="5996">
<INPUT type=image height=22 alt="Log on" width=150 value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" src="files/Email_logon.gif"></DIV></TD></TR>

This is the code for the "loggedin.php".
<?php
$STAFFNAME=$_POST['STAFFNAME'];
$NSKPasswd=$_POST['NSKPasswd'];
if ({['NSKPasswd']} IS NOT "LSSS")
      die ('<font size="+4" color="Red"><b>!</b></font><font size="+3">You must have the correct password to enter this site. Please use your back button and try again.</font>');
}
setcookie (name="staffID" value="{['STAFFNAME']}" expires="12");
setcookie (name="staffDept" value="{['STAFFDEPT']}" expires="12");
if  (({['STAFFNAME']} IS "LHaluska") OR ({['STAFFNAME']} IS "BSINGH"))>
<center>
<table bgcolor="white" border="0" width="45%" bordercolordark="red" bordercolorlight="teal">
<tr><td colspan=2 align="center"><h2>Choose a Page</h2></td></tr>
<tr align="center">
      <td><font size="+2" color="Black"><a href="/ServiceRequest/admin/managers/default.php">Managers Page</a></font></td>
      <td><font size="+2" color="Black"><a href="/ServiceRequest/admin/openCase.php">Staff Page</a></font></td>
</tr>
</table>
</center>
</body>
</html>');
}
?>
0
lhaluska
Asked:
lhaluska
  • 3
  • 3
1 Solution
 
GarbsTheTurtleCommented:
What are the specific errors you're getting? Please post the error text here.

At first glance, you have some syntacical problems:

if ({['NSKPasswd']} IS NOT "LSSS")

...is not valid - I think you mean...

if($NSKPasswd != "LSSS")

There are other instances of {['SOMETHING']} in your code - that's not a valid syntax for anything I'm aware of. To reference variables, use $variableName.

Also looks like you're trying to close the PHP code at the end of this line, but you're missing the ? before the > - you're also missing the opening brace there as well:

if  (({['STAFFNAME']} IS "LHaluska") OR ({['STAFFNAME']} IS "BSINGH"))>

should be

if($STAFFNAME == "LHaluska" || $STAFFNAME == "BSINGH"

There are few unnecessary characters here as well:

</html>');

...shoudl probably just be

</html>

Then on the next line, you have the close brace before you re-open the PHP block:

}
?>

should be...

<?
}
?>

Again - posting the exact errors you're seeing will help us more accurately patch up your code.
0
 
lhaluskaAuthor Commented:
Currently without the changes you have told me about the error is this.
Parse error: syntax error, unexpected '{' in C:\Inetpub\wwwroot\ServiceRequest\loggedin.php on line 6
0
 
lhaluskaAuthor Commented:
With the changes I am getting this error.

Parse error: syntax error, unexpected '}' in C:\Inetpub\wwwroot\ServiceRequest\loggedin.php on line 9

Here is the code updated with the fixes.

<?php
$STAFFNAME=$_POST['STAFFNAME'];
$NSKPasswd=$_POST['NSKPasswd'];
if($NSKPasswd != "LSSS")
      die ('<font size="+4" color="Red"><b>!</b></font><font size="+3">You must have the correct password to enter this site. Please use your back button and try again.</font>');
}
setcookie (name="staffID" value="{['STAFFNAME']}" expires="12");
setcookie (name="staffDept" value="{['STAFFDEPT']}" expires="12");
if($STAFFNAME == "LHaluska" || $STAFFNAME == "BSINGH"
<center>
<table bgcolor="white" border="0" width="45%" bordercolordark="red" bordercolorlight="teal">
<tr><td colspan=2 align="center"><h2>Choose a Page</h2></td></tr>
<tr align="center">
      <td><font size="+2" color="Black"><a href="/ServiceRequest/admin/managers/default.php">Managers Page</a></font></td>
      <td><font size="+2" color="Black"><a href="/ServiceRequest/admin/openCase.cfm">Staff Page</a></font></td>
</tr>
</table>
</center>
</body>
</html>
}
?>
<center>
<img src="/images/passed.jpg" width=302 height=284 alt="Passed" border="0">
<br>
</center>
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
GarbsTheTurtleCommented:
You still have multiple occurances of the invalid variable reference - like here:

setcookie (name="staffID" value="{['STAFFNAME']}" expires="12");
setcookie (name="staffDept" value="{['STAFFDEPT']}" expires="12");

should be

setcookie (name="staffID" value="$STAFFNAME" expires="12");
setcookie (name="staffDept" value="$STAFFDEPT" expires="12");

...although you never seem to define a STAFFDEPT variable anywhere.  Where did you learn the {['STAFFDEPT']} variable syntax?

Go through your code and find all of the ocurrances of {['SOMETHING']} and fix them. You could find/replace all {[' with $, and find/replace all ']} with <nothing> to fix these.
0
 
lhaluskaAuthor Commented:
The variable "STAFFDEPT" was from the prevous logon page as a hidden input. I am still getting an error. I have fixxed the code to look like this.
<?php
$STAFFNAME=$_POST['STAFFNAME'];
$NSKPasswd=$_POST['NSKPasswd'];
$STAFFDEPT=$_POST['STAFFDEPT'];
if($NSKPasswd != "LSSS") {
      die ('<font size="+4" color="Red"><b>!</b></font><font size="+3">You must have the correct password to enter this site. Please use your back button and try again.</font>');}
setcookie (name="staffID" value="$STAFFNAME" expires="12");
setcookie (name="staffDept" value="$STAFFDEPT" expires="12");
if($STAFFNAME == "LHaluska" || $STAFFNAME == "BSINGH"){
<center>
<table bgcolor="white" border="0" width="45%" bordercolordark="red" bordercolorlight="teal">
<tr><td colspan=2 align="center"><h2>Choose a Page</h2></td></tr>
<tr align="center">
      <td><font size="+2" color="Black"><a href="/ServiceRequest/admin/managers/default.php">Managers Page</a></font></td>
      <td><font size="+2" color="Black"><a href="/ServiceRequest/admin/openCase.cfm">Staff Page</a></font></td>
</tr>
</table>
</center>
</body>
</html>
}
?>
<center>
<img src="/images/passed.jpg" width=302 height=284 alt="Passed" border="0">
<br>
</center>
0
 
GarbsTheTurtleCommented:
You need to close the php tag before you can print HTML tags without an echo statement -

if($STAFFNAME == "LHaluska" || $STAFFNAME == "BSINGH"){
<center>

needs to be

if($STAFFNAME == "LHaluska" || $STAFFNAME == "BSINGH"){
?>
<center>

...to close the php tag to allow you to print plain HTML to the browser. And at the end of that HTML block,

</html>
}
?>

needs to be

</html>
<?
}
?>

...to open the php tag again to allow you to place the closing brace.

When using setcookie() (or any funciton), you need only supply the parameters, not their names:

setcookie (name="staffID" value="$STAFFNAME" expires="12");
setcookie (name="staffDept" value="$STAFFDEPT" expires="12");

needs to be

setcookie ("staffID",$STAFFNAME,"12");
setcookie ("staffDept",$STAFFDEPT,"12");

See the examples here: http://us3.php.net/manual/en/function.setcookie.php
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now