Domanda

I put in the information and click "Submit Query" to log in, it redirects me to a blank page.

  • I have already registered with the information im trying to login.

  • And checked in the database if the user exists. This is the code:

    <?php
    // ERROR DEBUG THINGY
    $showErrors = (isset($_GET['debug'])) ? true : false;
    
    if(!$showErrors) {
        ini_set('display_errors', 'Off');
    }
    else {
        error_reporting(E_ALL);
        ini_set('display_errors', 'On');
    }
    
    // DATABASE START
    $servername = "localhost";
    $username = "root";
    $conn = mysql_connect($servername, $username) or die (mysql_error());
    mysql_select_db("test", $conn);
    
    // WE START THE SESSION
    session_start();
    
    // START LOGIN PROCESS
    if(isset($_SESSION['logged'])) {
        print_secure_content(); //CONTENT THAT'S ECHOED ONCE YOU LOG IN
    }
    else {
        if(!$_SESSION['logging']) {       //IF LOGGING SESSION ISNT RUNNING
            $_SESSION['logging'] = true; //RETURNS THE USER BACK TO THE LOGIN FORM
            loginform();                //SHOWS THE LOGIN FORM
        }
        else if($_SESSION['logging']) {
            $numberOfRows = checkpass(); //CHECK IF THE USER ALREADY EXISTS
            if($numberOfRows == 1) {    //IF OLD USER LOG HIM IN
                $_SESSION['id'] = $_POST['username'];
                $_SESSION['logged'] = true;
                echo "<h1> You have logged in successfully </h1>";
                print_secure_content();
                print_user_details();
            }
            else {
                echo "You have entered a wrong username or password, please try again.<br />";
                loginform();
            }
        }
    }
    
    // DATABASE CLOSE
    mysql_close();
    
    // FUNCTIONS!!!
    
    function loginform() { //THE LOG IN FORM
        echo "Please login <br />
        <form method=\"POST\" action=\"?\">
                USERNAME<br />
                <input name='username' type='text'><br />
                PASSWORD<br />
                <input name='password' type='password'><br />
        <input type='submit' name='login'></form>
        <p><a href='registerform.php'> Register Here! </a></hr>";
    }
    
    function print_user_details() { //CHECK PASSWORD
        if(isset($_POST['username']) && isset($_POST['password'])) {
            $sql = "SELECT * FROM users WHERE name = '{$_POST['username']}' and password = '{$_POST['password']}'";
            $result = mysql_query($sql, $conn) or die (mysql_error());
            return mysql_num_rows($result);
        }
    }
    
    function checkpass() { //CHECK PASSWORD
        if(isset($_POST['username']) && isset($_POST['password'])) {
            $sql = "SELECT * FROM users WHERE name = '{$_POST['username']}' and password = '{$_POST['password']}'";
            $result = mysql_query($sql, $conn) or die (mysql_error());
            return mysql_num_rows($result);
        }
    }
    
    function print_secure_content() { // ECHO ONCE YOU LOG IN
        echo 'Hello '. $_SESSION['id'] .'!<br />';
        echo 'Only a logged in user can see this. <br /> <a href="logout.php"> Logout </a>';
    }
    

    ?>

È stato utile?

Soluzione

There might be some syntax Error.

Go to php.ini file
Change display_errors=off to on and save it.
Restart the server
Check in Front end. You might find the Error. Correct it.
Again Restart the Server to see your changes.

Altri suggerimenti

$sql = "SELECT * FROM users WHERE name = '".$_POST['username']."' and password = '".$_POST['password']."'";

user sql query like this

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top