?
Solved

Login page problem?

Posted on 2007-08-01
6
Medium Priority
?
236 Views
Last Modified: 2007-08-01
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
Comment
Question by:lhaluska
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:DrNikon224
ID: 19612086
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
 
LVL 1

Author Comment

by:lhaluska
ID: 19612121
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
 
LVL 1

Author Comment

by:lhaluska
ID: 19612170
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:DrNikon224
ID: 19612348
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
 
LVL 1

Author Comment

by:lhaluska
ID: 19612468
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
 
LVL 16

Accepted Solution

by:
DrNikon224 earned 2000 total points
ID: 19612528
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question