Hi,

I have the code below for a login script. I not finished it yet and i moved from Dreamweaver to Netbeans a while ago and all my code has lost it's indentation and formatting.

I am missing some curly bracelets i am sure of it but cannot find where i am missing them.

Could someone please be so kind and find the parse error for me please?

It says unexpected $end in C:\wamp\www\member\login.php on line 305. Not on line 305 thou as that is the last line.

I don't know how i managed to do it but obviously i did mess up with my curly bracelets i think. I have looked over and over it and my eyes are soar as i just cannot find where they are missing.

Thanks for any help.
PHPLOVER

<?php
//ob_start();

// Include config.php
require_once("".$_SERVER['DOCUMENT_ROOT']."/lib/config.php");

// top.inc.php
require_once($top_inc);
?>

<!-- Meta start -->
<title><?php echo $websitename; ?> - Member Login</title>
<meta name="description" content="<?php echo $websitename; ?> - Member Login" />
<meta name="keywords" content="<?php echo $websitename; ?>, login, signup, register, sign in, signin, sign up" />
<!-- Meta end -->

<?php
// main.inc.php
require_once($main_inc);
?>

<!-- CONTENT HERE -->


<?php
    // Check if form has been submitted
    if(isset($_POST['submit']) && $_SERVER['REQUEST_METHOD'] == 'POST'){

        # Connect to databse
        sql_con();

        # Get form data and cleanse
        $username = msqls(trim($_POST['username']));
        $password = msqls(trim($_POST['password']));
        $ip = msqls($_SERVER['REMOTE_ADDR']);

        # Validate form data
        if (utfstrlen($username) < 1) {
            $error .= "Please enter your username <br />";
        }
        if (utfstrlen($username) > 0 && !preg_match(constant("USERNAME_REGEX"), $username)) {
            $error .= "Username invalid format <br />";
        }
        if (utfstrlen($password) < 1) {
            $error .= "Please enter your password <br />";
        }
        if (utfstrlen($password) > 0 && !preg_match(constant('PASSWORD_REGEX'), $password)) {
            $error .= "Password invalid format<br />";
        }

        # If error founds display them
        if(isset($error)){
        $SiteErrorMessages = "$error";
        SiteErrorMessages();
        } # else no errors found continue processing
        else {
            # Check if user has activated there account
            $status_check = mysql_query("SELECT username FROM ".constant("TBL_USERS")."
            WHERE username = '$username' AND status = '".constant("USER_STATUS_VERIFY")."' LIMIT 1");

            # Check if user has requested account to be deleted
            $delete_check = mysql_query("SELECT username FROM ".constant("TBL_USERS")."
            WHERE username = '$username' AND status = '".constant("USER_STATUS_DELETE")."'
            AND password = '".sha1($password)."' LIMIT 1");

            # Check if user has been suspended
            $username_status_check = mysql_query("SELECT username, suspended_note FROM ".constant("TBL_USERS")."
            WHERE username = '$username' AND status = '".constant("USER_STATUS_SUSPENDED")."'
            AND password = '".sha1($password)."' LIMIT 1");

            # Check above queries if error occurs notify user
            if(!$delete_check || !$status_check || !$username_status_check){
            echo '<h1>Oops something went wrong :(</h1>';

            $SiteErrorMessages =
            "Something went wrong while processing your request. Please try again later.
            <br /> $websitename has been notified of this error and will investigate further.";

            SiteErrorMessages();

            # This variable will be passed to the site_errors_email_notification function
            $site_error_email_message_notification = "User Login Failure <br />
            A user tried to login but the verify, suspended or delete query check failed.
            <br /><br /><b>".mysql_error()."</b><br /><br />
            There details are below. <br /><br />
            Username: <b>$username</b> <br />";
            # This function will pass the above variable (message) to the admin error notify function
            # to send admin an email to notify them of an error
            site_errors_email_notification();

            include("$footer_inc");
            exit;
            } # else queries ok continue processing
            else {
                 # Check delete query
                 if (mysql_num_rows($delete_check) == 1) {
                 echo '<h1>Account Deletion In Process</h1>';
                 echo "<p><b>Sorry, you cannot login to your account as you requested your account to be deleted.</b>
                      <b>Your account is queued for deletion from the $websitename database and will be deleted within 24 hours.</b></p>";

                 echo "<p><b>$websitename sent you a confirmation email when you requested your account to be removed.</b>
                      <b>If you did not make this request via your account please <a href=\"../contactus.php\">contact us</a> immediately.</b></p>";

                 echo "<p><b>Please note that it may not be possible to recover your account as the process is automated.</b></p>";
                 header( 'refresh: 60; url=$websiteaddress' );
                 include ("$footer_inc");
                 exit;
                 }
                 # Check status query
                 elseif (mysql_num_rows($status_check) == 1) {
                 echo "<h1>Account Activation Required</h1>";
                 echo "<p><b>You must activate your account via email before you can login.</b></p>";
                 header( 'refresh: 10; url=resendactivationemail.php' );
                 include ("$footer_inc");
                 exit;
                }
                 # Check username status query
                 elseif (mysql_num_rows($username_status_check) == 1) {
                 $row = mysql_fetch_row($username_status_check);
                 echo "<h1>Account Suspended</h1>";
                 echo "<p>Dear <b>" . $row[0] . "</b>, <br />
                      Your account has been suspended. The administrator has left the
                      following message:</p>";

                 $no_suspended_note =
                 "The administrator has not left a message. <br />
                 If you feel your account has been suspended in error please contact $websitename <a href=\"/contactus.php\">here</a>.";

                 if (utfstrlen($row[1]) < 1) {
                    $SiteWarningMessages = "$no_suspended_note";
                    SiteWarningMessages();
                    include ("$footer_inc");
                    exit;
                 } else {
                    $SiteWarningMessages = " . $row[1] . ";
                    SiteWarningMessages();
                    echo '<p>If you feel your account has been suspended in error please contact ' . $websitename . ' <a href="/contactus.php">here</a>.<br />
                    <b>Please include your username when contacting ' . $websitename . '.</b></p>';
                    include ("$footer_inc");
                    exit;
                }
            } # else user must be ok to login so continue ...
            else {
                # Login Query
                $query = mysql_query("SELECT id, admin, username, first_name, last_name, email, last_visited,
                date_time, websiteurl, msn, aim, yim, twitter, gender
                FROM ".constant("TBL_USERS")." WHERE username = '$username' AND
                password = '".sha1($password)."' LIMIT 1");

                # Check login query
                if(!$query){
                    echo '<h1>Oops something went wrong</h1>';

                    $SiteErrorMessages =
                    "Something went wrong while trying to log you in. Please try again later.
                    <br /> $websitename has been notified of this error and will investigate further.";

                    SiteErrorMessages();

                    // This variable will be passed to the site_errors_email_notification function
                    $site_error_email_message_notification = "User Login Failure <br />
                    A user tried to login but the Login Verification Check failed.
                    <br /><br /><b>".mysql_error()."</b><br /><br />
                    There details are below. <br /><br />
                    Username: <b>$username</b> <br />";
                    # This function will pass the above variable (message) to the admin error notify function
                    # to send admin an email to notify them of an error
                    site_errors_email_notification();

                    include("$footer_inc");
                    exit;
            } # else login query ok so continue
            else {
                # Validate credentials against DB
                if (mysql_num_rows($query) == 1) {
                    $found_user = mysql_fetch_array($query);

                    # Tell them they are being logged in
                    echo '<h1>Your now being logged in ...</h1>';
                    $SiteSuccessMessages = '<a href=\"/member/cp.php\">Click here if you
                    do not automatically redirect</a>';

                    SiteSuccessMessages();

                    # User logged in succesfully reset failed login number to 0
                    $failed_login_reset = mysql_query("UPDATE ".constant("TBL_USERS")." SET
                    `failed_login_count` = '0', `ip` = '" . $ip . "'
                    WHERE `username` = '" . $username . "' LIMIT 1");

                    # check failed login query
                    if(!$failed_login_reset){
                    // This variable will be passed to the site_errors_email_notification function
                    $site_error_email_message_notification = "User Login Failure <br />
                    A user logged in but the failed login reset counter query failed.
                    <br /><br /><b>".mysql_error()."</b><br /><br />
                    There details are below. <br /><br />
                    Username: <b>$username</b> <br />";
                    # This function will pass the above variable (message) to the admin error notify function
                    # to send admin an email to notify them of an error
                    site_errors_email_notification();
                    }

                    # Store all member data into session to use for later on other areas of the website
                    $_SESSION['username'] = $found_user['username'];
                    $_SESSION['id'] = $found_user['id'];
                    $_SESSION['admin'] = $found_user['admin'];
                    $_SESSION['last_visited'] = date('l dS F Y, g:i:s A', $found_user['last_visited']);
                    $_SESSION['first_name'] = $found_user['first_name'];
                    $_SESSION['last_name'] = $found_user['last_name'];
                    $_SESSION['email'] = $found_user['email'];
                    $_SESSION['websiteurl'] = $found_user['websiteurl'];
                    $_SESSION['msn'] = $found_user['msn'];
                    $_SESSION['aim'] = $found_user['aim'];
                    $_SESSION['yim'] = $found_user['yim'];
                    $_SESSION['twitter'] = $found_user['twitter'];
                    $_SESSION['gender'] = $found_user['gender'];
                    $_SESSION['date_time'] = date('l dS F Y, g:i:s A', $found_user['date_time']);
                    $_SESSION['date_time_for_profile'] = $found_user['date_time'];
                    $_SESSION['time'] = time();
                    if (isset($_GET['redirect'])) {
                        redirect($websiteaddress . $_GET['redirect'], 2);
                    } else {
                        redirect("cp.php", "0");
                    }
                    include ("$footer_inc");
                    exit;
            } # else login details invalid
            else {
                # Login Details Invalid Error
                echo 'Login Details Invalid';

                # If user fails 3 logins lock there account
                $login_failure_query = mysql_query("SELECT username, email, failed_login_count,
                status FROM ".constant("TBL_USERS")." WHERE username = '$username' AND
                status = '".constant("USER_STATUS_ACTIVATED")."' LIMIT 1");

                # Check if query ok
                if(!$login_failure_query){

                    # This variable will be passed to the site_errors_email_notification function
                    $site_error_email_message_notification = "Login Failure Query <br />
                    A user tried to login but the Login Failure Query Check failed.
                    <br /><br /><b>".mysql_error()."</b><br /><br />
                    There details are below. <br /><br />
                    Username: <b>$username</b> <br />";
                    # This function will pass the above variable (message) to the admin error notify function
                    # to send admin an email to notify them of an error
                    site_errors_email_notification();

                    include("$footer_inc");
                    exit;

                } # else login_failure_query ok so continue ...
                else {
                    # Check
                    if (mysql_num_rows($login_failure_query) == 1) {
                        # Fetch user row
                        $row = mysql_fetch_row($login_failure_query);
                        # Store data in variables
                        $username_ = $row[0];
                        $email = $row[1];
                        # Increment failed login row by 1 on each failed login
                        $login_count = $row[2] + 1;
                        # Update failed_login_count row each time login fails
                        $update_login_number = mysql_query("UPDATE ".constant("TBL_USERS")." SET `failed_login_count`
                        = '" . $login_count . "' WHERE `username` = '" . $username . "'");
                        # Fetch total failed logins
                        $login_count_total = $row[2];
                }
            }
        }
    }
?>

<h1>Sign In to your account </h1>

<form action="login.php<?php if (isset($_GET['redirect']))
{ echo "?redirect=" . $_GET['redirect']; } ?>" method="post"
id="frmcontact">

    <label for="username">Username</label>
    <input type="text" name="username" id="username"
    value="<?php if (isset($username)) { echo $username; } ?>" class="textboxcontact" />

    <label for="password">Password</label>
    <input type="password" name="password" id="password" class="textboxcontact" />

    <label for="submit">&nbsp;</label>
    <input type="submit" name="submit" id="submit" value="Sign In" class="submitcontact" />

</form>

<!-- CONTENT FINISH -->

<?php
// footer.inc.php
require_once($footer_inc);

//ob_end_flush();
?>

I am going to have to find a tutorial on debugging in NetBeans, i love the software plus it's free which is even better but not benefiting from it's powerful features at the moment.

Recommended Answers

All 4 Replies

I didn't do anything that you couldn't have done which is to go through methodically, organize the indents and check that all of the curly braces are matched (Netbeans should help you to do that part). I had to add three more closing curly braces after line 272 to get them to match up. There was another problem with the form at line 277 but it's gone away and I don't know what I did that fixed it. My version of your code now shows no errors.

Maybe you are used to this style of coding but if you are having trouble debugging it yourself then maybe you are making it more complex than it needs to be. PHP let's you do things like you have done with the form action at line 277 (as an example) but personally, I'd make it simpler and not try to embed logic like this in order to derive a variable. It's up to you but personally, I'd rather keep it simple and straightforward because it will probably save time when there is a need to debug it. Just my opinion.

http://innovationsdesign.net/wb_2.7/pages/tech-resources/php-help.php#question_17

commented: Solved my problem. Some nice advice :) +1

Hi,

Thanks for helping i sorted it now with your help. Reason why i had a hard time with it as when i switched from DreamWeaver to NetBeans it lost it's formatting and indentation.

To be honest from all the books i have been reading and what i have learnt from online websites and friends this is how i have been taught to program so don't really know any other way. I can understand the code and am happy with it but wish i could learn from the real professionals who know what's best.

Not sure what you really mean by I'd make it simpler and not try to embed logic like this in order to derive a variable. Also when you say you like to keep it straightforward in what way do you mean?

Would appreciate if you could explain further as it could help me in future projects.

Thanks for you help and the advice.

PHPLOVER

I would have replaced line 273-279 with:

if (isset($_GET['redirect'])) {
     $wk = "?redirect=" . $_GET['redirect'];
}
else {
     $wk = ""
}
?>
 
<h1>Sign In to your account </h1>
 
<form action="login.php<php echo $wk; ?>" method="post"
id="frmcontact">

I am sure that there are those who will say that this isn't as efficient as your version and doesn't take full advantage of what PHP can do but I value my time more than machine cycles so I'd rather keep it simple and obvious. To each his own however; it's partly a matter of style and partly what you're used to and what makes you happy.

Oh rite i see what you mean. Thanks for the help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.