Page 1 of 1

Small Problem regarding login script.

Posted: Sat Feb 27, 2010 3:30 pm
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.

Re: Small Problem regarding login script.

Posted: Sat Feb 27, 2010 3:39 pm
by F00Baron
Line 23 has an extra semicolon. Take that out.

Re: Small Problem regarding login script.

Posted: Sat Feb 27, 2010 3:46 pm
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