Small Problem regarding login script.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rAPTUREEE
Forum Newbie
Posts: 1
Joined: Sat Feb 27, 2010 3:26 pm

Small Problem regarding login script.

Post by rAPTUREEE »

Hello all,

Just wondering if I could pick some brains, I'm currently learning PHP and have been messing around with a fun project, currently developing a simple login / register script.

The error that I keep getting is -

Parse error: syntax error, unexpected T_ELSE in /home/danhumph/public_html/smithy/login.php on line 27


Can't for the life of me work out what's missing in this code:

Code: Select all

<?php 
//connect to db
$conn = mysql_connect("localhost", "blah", "blah") or die(mysql_error());
mysql_select_db("blah") or die(mysql_error());
 
//declares variable
$username=$_POST["username"]; 
$password = $_POST["password"];
 
$result = mysql_query ("SELECT * FROM users WHERE username = '$username' AND password = '$password' AND isadmin = '$isadmin'");
$isadmin = mysql_query ("SELECT * FROM users WHERE username = '$username' AND password = '$password' AND isadmin = '$isadmin'");
 
if (mysql_num_rows($result)==0) {
 
 
    echo "No matching rows from the database!"; }
 
 
while ($row = mysql_fetch_array($isadmin)){
 
if 
 
 ($row["isadmin"]==1);
    echo "You are logged in as administrator"  or die(mysql_error());
}
 
else 
 
    $_SESSION["gatekeeper"] = $username;
    header ("Location: index.php");
 
?>
 
Thanks in Advance,

Dan.
User avatar
F00Baron
Forum Newbie
Posts: 6
Joined: Sat Feb 20, 2010 11:43 am

Re: Small Problem regarding login script.

Post by F00Baron »

Line 23 has an extra semicolon. Take that out.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Small Problem regarding login script.

Post by mikosiko »

and in addition to the previous post... this group of lines have unbalanced "{" you are not clossing them properly.

Code: Select all

[color=#FF0000]while ($row = mysql_fetch_array($isadmin)){
 
if 
 
 ($row["isadmin"]==1);
    echo "You are logged in as administrator"  or die(mysql_error());
}
 
else 
 
    $_SESSION["gatekeeper"] = $username;
    header ("Location: index.php");
 [/color]
and in top of that the "or die(mysql_error()" after the echo is incorrect

just for start.... code hace other errors too.... as per example... why are you doing the same select twice?... don't look good
Post Reply