0

Okay I have put together the most SIMPLE form and database possible in order to hopefully get some guidance in debugging PHP.

LoginForm.php:

    <?php
session_start();

$conn = new PDO('mysql:host=localhost;dbname=login', 'root', '');

if (isset($_POST['login']))
{

    $username = $_POST['username'];
    $password = $_POST['password'];

    $query = $conn->prepare("SELECT COUNT('id') FROM 'users' WHERE 'username' = '$username' AND 'password' = '$password'");
    $query->execute();

    $count = $query->fetchColumn();

    if ($count == "1")

    {

        $_SESSION['username'] = $username;

        header('location: Form.php');

    }

}

?>

//THIS IS FORM - This code is underneath the code above.

<html

<head>Welcome to the Gym Login System</head>

<body>
    <div id="Form">
        <form method = "post" name="login">

            <p>
                <label>Email:</label>
                <input type="text"  name ="username" />
            </p>
            <p>
                <label>Password:</label>
                <input type="text" name="password"  />
            </p>
            <p>
                <input type ="submit" name="login" value ="Login" />
            </p>


</form>
</div>


</body>
</html>

I have created a user in the database "login" in the table "users" with the following: username:test, password:test123

I tried to use this user to log into the "website to be" (only practicing), however the page loginForm.php page just refreshes, but it should have taken me to Form.php? Let me know if you need anymore information.

  • 1
    Also, learn some HTML first :) – Chay22 May 14 '16 at 23:13
  • `a)` you don't seem to be using prepared statements correctly. `b)` if the code you gave was to try to redirect to `Form.php` and it's not once the form is being submitted, add a `action="Form.php"` in the form and on submittion it'll be sent to that page. :) – Jack Hales May 14 '16 at 23:15
  • @Jek Thanks for trying to help me mate. The Form.php is the UI that any registered user can access. This means that the login information will need to be correct first and only then is the user directed to Form.php. – Joshy Dowrick May 14 '16 at 23:19
  • @JoshyDowrick add me on skype (jackhalesyy) and I can try and help you yeah? Just I can't answer the question now haha – Jack Hales May 14 '16 at 23:21
  • I have no idea why this was marked as a duplicate. Okay I will add you. – Joshy Dowrick May 14 '16 at 23:25

0 Answers0