Simple login without encryption in PHP

I'm making a very simple login script (beginner at PHP) and here is my code. I can't figure out how to redirect after true login credentials. I know this probably is a duplicate but I can't figure this out without help on my exact script (as mentioned above I'm not that good).

update: So I have fixed name in password, form method, and the redirect . But now I'm getting to a empty page, something is wrong with my function as one comment earlier. I'm also a dummie at MySQL can someone help me further? My code is updated

Another update Okay so i have finished all of my script, but the problem is my sql functions. So does anyone know mysqli and can translate it?

    <?php $tilkobling = mysqli_connect("localhost","root","root","login_form");

    if(isset($_POST["name"], $_POST["password"]))

            $name = $_POST["name"];
            $password = $_POST["password"];

            $result1 = mysql_query("SELECT username, password
                                    FROM user
                                    WHERE username = '".$name."'
                                    AND  password = '".$password."'");

            if(mysql_num_rows($result1) > 0 )
                $_SESSION["logged_in"] = true;
                $_SESSION["naam"] = $name;
                header("Location: information_site.php");
                echo 'The username or password are incorrect!';

    <!DOCTYPE html>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <h2>bypass to <a href="information_site.php">information site</a></h2>
        <div class="login-page">
          <div class="form">

            <form method="post" class="login-form">
              <input name="name" type="text" placeholder="username"/>
              <input name="password" type="password" placeholder="password"/>
              <button name="submit">login</button>
              <p class="message">Not registered? <a href="create_an_account.php">Create an account</a></p>

        <script type="text/javascript">
              $('.message a').click(function(){
           $('form').animate({height: "toggle", opacity: "toggle"}, "slow");

3 answers

  • answered 2018-03-13 20:19 Brxxn

    Your header needs to be in the true portion of the if/else, which is where you set your $_SESSION variables, here you are:

            if(mysql_num_rows($result1) > 0 )
                $_SESSION["logged_in"] = true;
                $_SESSION["naam"] = $name;
                header("Location: information_site.php");

  • answered 2018-03-13 20:19 Jelle 3.0

    Have you Tried the HTML meta tag, this subtitutes the header() function. Of course initially convert it into PHP code. Like this:

    Echo "<meta http-equiv='refresh' content='0; URL=put your url in here to the page you like to redirect to'>" ;

    This should probably operate correctly.

  • answered 2018-03-13 20:19 Seif Hatem

    You're using mysqli connector and mysql functions so let's assume you'll use mysql for all

    $tilkobling = mysql_connect("localhost","root","root");

    mysql_select_db( "login_form", $tilkobling );

    and you'll need to add session_start() before using/setting any session variables


    $_SESSION["logged_in"] = true;