Jump to content

Recommended Posts

Hey, brand new to all this, this is actually my first attempt at doing PHP, so I'm having trouble with this one spot. I get this error: Parse error: parse error, unexpected T_DEFAULT in *********/**********/html/login.php on line 166.

 

I did go through the boards here and tried some of the other solutions I read, but nothing is working.

 

I'm going to paste the php here, but if that's not what I am supposed to do let me know how to show you all what I did. Thanks for any help in advance.

 

<?php

/*program: login.php

desc: login program for the Locker Room section of lapgrinder.  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();

include("shoes.inc");

switch(@$_POST['do'])

{

case "login":

$cxn = mysql_connect($host, $user, $password, $dbname) or die ("Couldn't connect to server.");

 

$sql = "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]'";

$result = mysql_query($cxn,$sql) or die ("Couldn't execute query.");

$num = mysql_num_rows($result);

if($num > 0) // login name was found

{

$sql= "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]' AND password=md5('$_POST[fpassword]')";

$result2 = mysql_query($cxn,$sql) or die ("Couldn't execute query 2.");

$num2 = mysql_num_rows($result2);

if ($num2 > 0) //password is correct

{

$_SESSION['auth']="yes";

$logname=$_POST['fusername'];

$_SESSION['logname'] = $logname;

$today = date("Y-m-d h:i:s");

$sql = "INSERT INTO Login (loginNam, loginTime) VALUES ('$logname','$today')";

$result = mysql_query($cxn,$sql) or die ("can't excute insert query.");

header("location: Member_page.php");

}

else //password is not correct

{

$message="The Login Name or password is not correct! Please try again!.<br />";

include("lockerroomlogin.php");

}

}

elseif ($num == 0) //login name not found

{

$message = "The Login Name you entered does not exist! Please try again.<br>";

include("lockerroomlogin.php");

}

break;

 

case "new":

/* Check for blanks */

foreach($_POST as $field => $value)

{

if ($field != "fax")

{

if ($value == "")

{

$blanks[] = $field;

}

}

}

if(isset ($blanks))

{

$message_new = "The following fields are blank. Please enter the required information: ";

foreach($blanks as $value)

{

$message_new .= "$value, ";

}

extract($_POST);

include("lockerroomlogin.php");

exit();

}

/*Validate data*/

foreach($_POST as $field => $value)

{

if(!empty($value))

{

if(eregi("name",$field) and !eregi("login",$field))

{

if (!ereg("^[A-Za-z' -]{1,50}",$value))

{

$errors[]="$value is not a valid name.";

}

}

if(eregi ("state",$field) or eregi("city",$field))

{

if(!ereg("^[A-Za-z]{2,50}",$value))

{

$errors[] = "$value is not a valid city or state.";

}

}

if(eregi("email",$field))

{

if(!ereg("^.+@.+\\..+$",$value))

{

$errors[] = "$value is not a valid email address.";

}

}

} // end if empty

}// end foreach

if(@is_array($errors))

{

$message_new ="";

foreach($errors as $value)

{

$message_new .= $value."Please try again<br />";

}

extract($_POST);

include("lockerroomlogin.php");

exit();

/*clean data*/

$cxn = mysql_connect($host,$user,$passwd,$dbname);

foreach($_POST as $field => $value)

{

if($field != "button" and $field != "do")

{

if($field == "password")

{

$password = strip_tags(trim($value));

}

else

{

$fields[]=$field;

$value = strip_tags(trim($value));

$values[] =

mysql_real_escape_string($cxn,$value);

$$field = $value;

}

}

}

/*check whether user name already exists*/

$sql = "SELECT loginName FROM Member WHERE loginName = '$loginName'";

$result = mysql_query($cxn,$sql) or die ("Couldn't execute select query.");

$num = mysql_num_rows($result);

if($num > 0)

{

$message_new = "$loginName already in use. Please select another name.";

include("lockerroomlogin.php");

exit();

}

/*Add a new member to database*/

else

{

$today = date("Y-m-d");

$fields_str = implode(",",$fields);

$values_str = implode('","',$values);

$fields_str .=",createDate";

$values_str .='"'.",".'"'.$today;

$fields_str .=",password";

$values_str .='"'.","."md5"."('".$password."')";

$sql = "INSERT INTO Member ";

$sql .= "(".$fields_str.")";

 

$sql .= " VALUES ";

$sql .= "(".'"'.$values_str.")";

$result = mysql_query($cxn,$sql) or die ("Couldn't execute insert query.");

$_SESSION['auth']="yes";

$_SESSION['logname'] = $loginName;

 

/*send and e-mail to new member*/

$emess = "A new member account has been set up. ";

$emess.= "Your new Member ID and password are:";

$emess.= "\n\n\t$loginName\n\t$password\n\n";

$emess.="We appreciate you joinging Lapgrinder.com and the Locker Room";

$emess.="If you have any questions or problems, email grindersupport@lapgrinder.com";

$ehead="From: contact@lapgrinder.com\r\n";

$subj = "Your Locker Room Login Information";

$mailsnd=mail("$email","$subj","$emess","$ehead");

header("location:new_member.php");

}

break;

 

default:

  include("lockerroomlogin.php");

}

?>

Link to comment
https://forums.phpfreaks.com/topic/73693-trouble-with-a-loginregister-script/
Share on other sites

You never closed the brackets for this IF statement.

if (@is_array($errors)) {

 

Here is a better visual of your code, just to make it easier to read

 

<?php
/*program: login.php
desc: login program for the Locker Room section of lapgrinder.  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();
include("shoes.inc");
switch (@$_POST['do']) {
case "login":
    $cxn = mysql_connect($host, $user, $password, $dbname) or die("Couldn't connect to server.");
    
    $sql = "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]'";
    $result = mysql_query($cxn,$sql) or die("Couldn't execute query.");
    $num = mysql_num_rows($result);
    if($num > 0) // login name was found
    {
        $sql= "SELECT loginName FROM Member WHERE loginName='$_POST[fusername]' AND password=md5('$_POST[fpassword]')";
        $result2 = mysql_query($cxn,$sql) or die("Couldn't execute query 2.");
        $num2 = mysql_num_rows($result2);
        if($num2 > 0) //password is correct
        {
            $_SESSION['auth']="yes";
            $logname=$_POST['fusername'];
            $_SESSION['logname'] = $logname;
            $today = date("Y-m-d h:i:s");
            $sql = "INSERT INTO Login (loginNam, loginTime) VALUES ('$logname','$today')";
            $result = mysql_query($cxn,$sql) or die("can't excute insert query.");
            header("location: Member_page.php");
        } else //password is not correct
        {
            $message="The Login Name or password is not correct! Please try again!.
";
            include("lockerroomlogin.php");
        }
    } else if($num == 0) //login name not found
    {
        $message = "The Login Name you entered does not exist! Please try again.
";
        include("lockerroomlogin.php");
    }
    break;
    
case "new":
    /* Check for blanks */
    foreach($_POST as $field => $value)
    {
        if ($field != "fax") {
            if ($value == "") {
                $blanks[] = $field;
            }
        }
    }
    if (isset($blanks)) {
        $message_new = "The following fields are blank. Please enter the required information: ";
        foreach($blanks as $value)
        {
            $message_new .= "$value, ";
        }
        extract($_POST);
        include("lockerroomlogin.php");
        exit();
    }
    /*Validate data*/
    foreach($_POST as $field => $value)
    {
        if (!empty($value)) {
            if (eregi("name",$field) and !eregi("login",$field)) {
                if (!ereg("^[A-Za-z' -]{1,50}",$value)) {
                    $errors[]="$value is not a valid name.";
                }
            }
            if (eregi("state",$field) or eregi("city",$field)) {
                if (!ereg("^[A-Za-z]{2,50}",$value)) {
                    $errors[] = "$value is not a valid city or state.";
                }
            }
            if (eregi("email",$field)) {
                if (!ereg("^.+@.+\\..+$",$value)) {
                    $errors[] = "$value is not a valid email address.";
                }
            }
        }
        // end if empty
    }
    // end foreach
    if (@is_array($errors)) {
        $message_new ="";
        foreach($errors as $value)
        {
            $message_new .= $value."Please try again
";
        }
        extract($_POST);
        include("lockerroomlogin.php");
        exit();
        /*clean data*/
        $cxn = mysql_connect($host,$user,$passwd,$dbname);
        foreach($_POST as $field => $value)
        {
            if ($field != "button" and $field != "do") {
                if ($field == "password") {
                    $password = strip_tags(trim($value));
                } else {
                    $fields[]=$field;
                    $value = strip_tags(trim($value));
                    $values[] =
                    mysql_real_escape_string($cxn,$value);
                    $$field = $value;
                }
            }
        }
        /*check whether user name already exists*/
        $sql = "SELECT loginName FROM Member WHERE loginName = '$loginName'";
        $result = mysql_query($cxn,$sql) or die("Couldn't execute select query.");
        $num = mysql_num_rows($result);
        if ($num > 0) {
            $message_new = "$loginName already in use. Please select another name.";
            include("lockerroomlogin.php");
            exit();
        }
        /*Add a new member to database*/
        else
        {
            $today = date("Y-m-d");
            $fields_str = implode(",",$fields);
            $values_str = implode('","',$values);
            $fields_str .=",createDate";
            $values_str .='"'.",".'"'.$today;
            $fields_str .=",password";
            $values_str .='"'.","."md5"."('".$password."')";
            $sql = "INSERT INTO Member ";
            $sql .= "(".$fields_str.")";
            
            $sql .= " VALUES ";
            $sql .= "(".'"'.$values_str.")";
            $result = mysql_query($cxn,$sql) or die("Couldn't execute insert query.");
            $_SESSION['auth']="yes";
            $_SESSION['logname'] = $loginName;
            
            /*send and e-mail to new member*/
            $emess = "A new member account has been set up. ";
            $emess.= "Your new Member ID and password are:";
            $emess.= "\n\n\t$loginName\n\t$password\n\n";
            $emess.="We appreciate you joinging Lapgrinder.com and the Locker Room";
            $emess.="If you have any questions or problems, email grindersupport@lapgrinder.com";
            $ehead="From: contact@lapgrinder.com\r\n";
            $subj = "Your Locker Room Login Information";
            $mailsnd=mail("$email","$subj","$emess","$ehead");
            header("location:new_member.php");
        }
        break;
        
        default:
        include("lockerroomlogin.php");
    }
    ?>

 

Note, I didn't close that bracket for you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.