Home loginFile.php returns empty screen when loging in
Reply: 0

loginFile.php returns empty screen when loging in

Robin J
1#
Robin J Published in 2017-12-07 23:08:56Z

When I run this log in file on localhost and push submit (no matter if anything is typed in or not) i get the admin options. When I run this on the server and push submit, I get an empty screen with connected successfully from the dbConnect.php connection file. I have a database set up for this but it seems to me like the php document isn't checking against the database.

Here's the code:

    <?php 
session_cache_limiter('none');          //This prevents a Chrome error when using the back button to return to this page.
session_start();

    if ($_SESSION['validUser'] == "yes")                //is this already a valid user?
    {
        //User is already signed on.  Skip the rest.
        $message = "Welcome Back! $username";   //Create greeting for VIEW area     
    }
    else
    {
        if (isset($_POST['submit']) )           //Was this page called from a submitted form?
        {
            $inUsername = $_POST['username'];   //pull the username from the form
            $inPassword = $_POST['password'];   //pull the password from the form

            include 'dbConnect.php';                //Connect to the database
        try{
            $sql = $conn->prepare("SELECT event_user_name,event_user_password FROM event_log_in WHERE event_user_name = 'root' AND event_user_password = 'wdv341'") or die('<p>SQL String: $sql</p>');          


            //$query = $conn->prepare($sql) or die("<p>SQL String: $sql</p>");  //prepare the query

            $sql->bindParam(':username',$_POST['username']);
            $sql->bindParam(':password',$_POST['password']);//bind parameters to prepared statement

            $sql->execute() or die("<p>Execution </p>" );

            $result = $sql->setFetchMode(PDO::FETCH_ASSOC); 


            //echo "<h2>Username: $username</h2>";
            //echo "<h2>Password: $password</h2>";

            //echo "<h2>Number of rows affected " . $connection->affected_rows . "</h2>";   //best for Update,Insert,Delete         
            //echo "<h2>Number of rows found " . $sql->num_rows . "</h2>";              //best for SELECT
    }
        catch(PDOException $e) {
            echo "Error: " . $e->getMessage();
        }
            if ($_SESSION['validUser'] == "yes" )       //If this is a valid user there should be ONE row only
            {

                $_SESSION['validUser'] = "yes";             //this is a valid user so set your SESSION variable
                $message = "Welcome Back! $inUsername";
                //Valid User can do the following things:
            }
            else
            {
                //error in processing login.  Logon Not Found...
                $_SESSION['validUser'] = "no";                  
                $message = "Sorry, there was a problem with your username or password. Please try again.";
            }           

            $sql = null;
            $conn = null;

        }//end if submitted
        else
        {
            //user needs to see form
        }//end else submitted

    }//end else valid user

//turn off PHP and turn on HTML
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WDV341 Intro PHP - Login and Control Page</title>

<!--  User Login Page

if user is valid (Session variable - already logged on)
    display admin options
else
    if form has been submitted
        Get input from $_POST
        Create SELECT QUERY
        Run SELECT to determine if they are valid username/password
        if user if valid
            set Session variable to true
            display admin options
        else
            display error message
            display login form
    else
    display login form

-->

<body>

<?php



    if ($_SESSION['validUser'] == true) //This is a valid user.  Show them the Administrator Page
    {

//turn off PHP and turn on HTML
?>
        <h3>Presenters Administrator Options</h3>
        <p><a href="contactForm1.php">Input New Contact</a></p>
        <p><a href="selectEvents.php">List of Contacts</a></p>
        <p><a href="logingOut.php">Logout of Contacts Admin System</a></p>  

<?php
    }
    else                                    //The user needs to log in.  Display the Login Form
    {
?>

    <form name = "form1" id = "form1" method = "post" action = "loginFile.php">
        <p><b>Please log in for administrator options</p>
        <p>Please enter your username:
            <input type = "text" name = "username" id = "username">
        </p>
        <p>Please enter your password:
            <input type = "text" name = "password" id = "password">
        </p>

        <input type = "submit" name = "submit" id = "submit" value = "LOGIN">
    </form>

    <?php //turn off HTML and turn on PHP
    }//end of checking for a valid user

    //turn off PHP and begin HTML           
    ?>

<p>Return to <a href='#'>www.presentationstogo.com</a></p>
</body>

</html>

database connection:

<?php
    session_start();

    $servername = "localhost";
    $username = "nephilim42_341";
    $password = "nephilim42";
    $dbname = "nephilim42_341";


try{
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected Successfully...";
    } 
catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}

?>

I've researched the crap out of this and I've found answers that were close, but not a fix. Any help would be awesome. Thank you.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313818 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO