Click here to Skip to main content
15,886,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to authorise one email id to login form which will provide access to admin page. but getting error:
Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\gregister\login-exec.php on line 79

Line 79 is above the //login failed in the code.

Please check and solve my code .


PHP
<?php
    //Start session
    session_start();

    //Include database connection details
    require_once('config.php');

    //Array to store validation errors
    $errmsg_arr = array();

    //Validation error flag
    $errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    //Sanitize the POST values
    $user_email = clean($_POST['user_email']);
    $pwd = clean($_POST['password']);

    //Input Validations
    if($user_email == '') {
        $errmsg_arr[] = 'Login ID missing';
        $errflag = true;
    }
    if($pwd == '') {
        $errmsg_arr[] = 'Password missing';
        $errflag = true;
    }

    //If there are input validations, redirect back to the login form
    if($errflag) {
        $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        session_write_close();
        header("location: login-form.php");
        exit();
    }

    //Create query
    $qry="SELECT * FROM customer WHERE user_email='$user_email' AND password='$pwd' ";

$result=mysql_query($qry);

    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) == 1) {
            //Login Successful
            session_regenerate_id();
            $customer = mysql_fetch_assoc($result);
            $_SESSION['SESS_id'] = $customer['id'];
            $_SESSION['SESS_fname'] = $customer['first_name'];
            $_SESSION['SESS_lname'] = $customer['last_name'];

            if (isset($_SESSION['SESS_user_email']) && $_SESSION['user_email'] == "harpuneet12@yahoo.com"){
            header("Location:admin-index.php");
            }
            else {
                    session_write_close();
            header("location: member-index.php");
            exit();
        }else {
            //Login failed
            header("location: login-failed.php");
            exit();
        }
    }else {
        die("Query failed");
    }
?>


[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 5-Apr-12 5:59am
v2
Comments
OriginalGriff 5-Apr-12 11:59am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Peta2010 5-Apr-12 12:02pm    
Sir, please tell me solution , i am struck at this stage from last one week, not getting any proper way to set this email id for admin page. thanks and appreciate for your help.

1 solution

Looks like your missing a closing brace right after
PHP
header("location: member-index.php");
exit();
 
Share this answer
 
v2
Comments
Peta2010 5-Apr-12 22:41pm    
yes i missed the braces but after that it working but every time takes me to member page. But i want to authorize above email id for admin page. Still at same stage ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900