Login form

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
How come i get this error
Parse error: parse error in /data/hosted/oni105/Login.php on line 20
when my form looks like this
<?php
/* Program: Login.php
Desc: Login program for the Members Only section of the
wesite. It provides two options: (1) login using an
existing Login Name and (2) enter a new login name. Login
Names and passwords are stored in a MySQL database.
*/
session_start();
session_register('auth');
session_register('username');
include("dogs.inc");
switch (@$do)
{
case "login":
$connection = mysql_connect($host, $user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die (Couldn't select database.");
$sql = "SELECT loginName FROM members
WHERE loginName='$fusername'"
$result = mysql_query($sql)
or die("Couldn't execute query.");
$num = mysql_num_rows($result);
if ($num ==1) // login name was found
{
$sql = "SELECT loginName From members
WHERE loginName='$fusername'
AND password=password('$fpassword')";
$result2 = mysql_query($sql)
or die("Couldn't execute query.");
$num2 = mysql_num_rows($result2);
if ($num2 > 0) // password is correct
{
$auth="yes";
$logname=$fusername;
$today = date("Y-m-d h:m:s");
$sql = "INSERT INTO Login (loginName, loginTime)
VALUES ('$logname','$today')";
mysql_query($sql) or die(Can't execute query.");
header("Location: Member_page.php");
}
else // password is not correct
{
unset($do);
$message="The Login Name, '$fusername' exists,
but you have not entered the correct
password! Please try again.<br>";
include("login_form.inc");
}
}
elseif ($num == 0) // login name not found
{
unset($do);
$message = "The Login Name you entered does not
exist! Please try again.<br>";
include("login_form.inc");
}
break;

case "new":
foreach($HTTP_POST_VARS as $key => $value)
}
if (!ereg("^.+@.+\\..+$",$email))
{
unset($do);
$message_new = "$email is not a valid email address.
Please try again.";
include("login_form.inc");
exit();
}
/* check to see if login name already exists */
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die (Couldn't select database.");
$sql = "SELECT loginName FROM members
WHERE loginName='$newname'";
$result = mysql_query($sql)
or die("Couldn't execute query.");
$num = mysql_numrows($result);
if ($num > 0)
{
unset($do);
$message_new = "$newname already used. Select another
loginName.";
include("login_form.inc");
exit();
}
else
{
$today = time("Y-m-d");
$sql = "INSERT INTO members (loginName,password,firstName,
email) VALUES
('$newname','$today',password('$newpass'),
'$firstName','$email')";
mysql_query($sql);
$auth="yes";
$logname = $newname;
/* send email to new member */
$emess1=" A new member account has been setup for you. ";
$emess2="Your new loginName and password are: ";
$emess3="\n\n\t$loginName\n\t$newpass\n\n";
$emess4="I appreciate your interest in my game ";
$emess5="at http://www.hostultra.com/~oni105";
$emess6="If you have any questions or problems, email ";
$emess7="adumbleton2003@lycos.co.uk";
$emess =
$emess1.$emess2.$emess3.$emess4.$emess5.$emess6.$emess7:
$ehead="From: FarmersInc\r\n";
$subject = "Your new account";
$mailsend=mail("$email","$subject","$emess","$ehead");
header("Location: New_member.php");
}
break;

default:
include("login_form.inc");
}
?>
 
*** Line with the following ***
$db = mysql_select_db($database, $connection)
or die (Couldn't select database.");

should be:
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");

You are missing your "

that was an error around line 20...if that does not work, just let us know.

good luck
 
im now getting this reply
Parse error: parse error in /data/hosted/oni105/Login.php on line 21
 
im now getting this
Parse error: parse error in /data/hosted/oni105/Login.php on line 64
when it looks like this
case "new";
foreach($HTTP_POST_VARS as $key => $value)
{
if (!ereg("^.+@.+\\..+$",$email))
}
unset($do);
$message_new = "$email is not a valid email address.
Please try again.";
include("login_form.inc");
exit();
{
/* check to see if login name already exists */
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
 
In the code from your first post, you have a foreach and a closing bracket right after it. You may have already fixed this, but I just wanted to make sure this wasn't the problem.
***
foreach($HTTP_POST_VARS as $key => $value)
}
***

good luck
 
It looks like everything in this is opened/closed. It looks that way in my editor anyway. You may want to give this a try and tell us what errors you are getting for it.

Code:
<?php
/* Program: Login.php
Desc: Login program for the Members Only section of the
wesite. It provides two options: (1) login using an
existing Login Name and (2) enter a new login name. Login
Names and passwords are stored in a MySQL database.
*/
session_start();
session_register('auth');
session_register('username');
include("dogs.inc");
switch (@$do)
{
    case "login":
        $connection = mysql_connect($host, $user,$password)
        or die ("Couldnt connect to server.");
        $db = mysql_select_db($database, $connection)
        or die ("Couldnt select database.");
        $sql = "SELECT loginName FROM members
        WHERE loginName='$fusername'"
        $result = mysql_query($sql)
        or die("Couldnt execute query.");
        $num = mysql_num_rows($result);
        if ($num ==1) // login name was found
        {
            $sql = "SELECT loginName From members
            WHERE loginName='$fusername'
            AND password=password('$fpassword')";
            $result2 = mysql_query($sql)
            or die("Couldnt execute query.");
            $num2 = mysql_num_rows($result2);
            if ($num2 > 0) // password is correct
            {
                $auth="yes";
                $logname=$fusername;
                $today = date("Y-m-d h:m:s");
                $sql = "INSERT INTO Login (loginName, loginTime)
                VALUES ('$logname','$today')";
                mysql_query($sql) or die("Cant execute query.");
                header("Location: Member_page.php");
            }
            else // password is not correct
            {
                unset($do);
                $message="The Login Name, '$fusername' exists,
                but you have not entered the correct
                password! Please try again.<br>";
                include("login_form.inc");
            }
        }
        elseif ($num == 0) // login name not found
        {
            unset($do);
            $message = "The Login Name you entered does not
            exist! Please try again.<br>";
            include("login_form.inc");
        }
    break;

    case "new":
        foreach($HTTP_POST_VARS as $key => $value)
        {
            if (!ereg("^.+@.+\\..+$",$email))
            {
                unset($do);
                $message_new = "$email is not a valid email address.
                Please try again.";
                include("login_form.inc");
                exit();
            }
            /* check to see if login name already exists */
            $connection = mysql_connect($host,$user,$password)
            or die ("Couldnt connect to server.");
            $db = mysql_select_db($database, $connection)
            or die ("Couldnt select database.");
            $sql = "SELECT loginName FROM members
            WHERE loginName='$newname'";
            $result = mysql_query($sql)
            or die("Couldnt execute query.");
            $num = mysql_num_rows($result);
            if ($num > 0)
            {
                unset($do);
                $message_new = "$newname already used. Select another loginName.";
                include("login_form.inc");
                exit();
            }
            else
            {
                $today = time("Y-m-d");
                $sql = "INSERT INTO members (loginName,password,firstName,
                email) VALUES
                ('$newname','$today',password('$newpass'),
                '$firstName','$email')";
                mysql_query($sql);
                $auth="yes";
                $logname = $newname;
                /* send email to new member */
                $emess1=" A new member account has been setup for you. ";
                $emess2="Your new loginName and password are: ";
                $emess3="\n\n\t$loginName\n\t$newpass\n\n";
                $emess4="I appreciate your interest in my game ";
                $emess5="at www.hostultra.com/~oni105";
                $emess6="If you have any questions or problems, email ";
                $emess7="adumbleton2003@lycos.co.uk";
                $emess =
                $emess1.$emess2.$emess3.$emess4.$emess5.$emess6.$emess7:
                $ehead="From: FarmersInc\r\n";
                $subject = "Your new account";
                $mailsend=mail($email,$subject,$emess,$ehead);
                header("Location: New_member.php");
                exit();
            }
        }
        break;

    default:
        include("login_form.inc");
}
?>
 
Parse error: parse error in /data/hosted/oni105/Login2.php on line 21
 
One thing you might want to also look at is the dogs.inc script. I think the way it works is if you include it, it will open/read the file. Perhaps it has the parse error in the dogs.inc file and since it is being included from the login2.php script, it is giving the error as a parse error in the login script. I'm not sure if this is the case, just taking a guess. Might be something you want to look at.

Oh wait...just noticed, the line 20 does not end with a ;

$sql = "SELECT loginName FROM members
WHERE loginName='$fusername'"

should be

$sql = "SELECT loginName FROM members
WHERE loginName='$fusername'";

hope this fixes it. Good luck
 
Back
Top