-2

i am trying to login but it seems that my variables dont contain anthing. i encountered this problem before but i managed to fix that , name attribute was missing in my html form that time..but this time don't know where am i doing wrong .plz help?

here is my html snippet. its returning blank even after i submit:

 <form action="onlogin.php" method="post">
                <h1>Login Form</h1>
                <div>
                    <input type="text" placeholder="Username" required="" name="username" />
                </div>
                <div>
                    <input type="password" placeholder="Password" required="" name="password" />
                </div>
                <div>
                    <input type="submit" value="Log in" />
                    <a href="#">Lost your password?</a>
                    <a href="signup.html">Register</a>
                </div>
            </form>

and my php snippet is:

    <?php
      include ("config/config.php");//connects to db successfully
      if(isset($_POST["submit"]))
       {
       $username =  $_POST['username']; echo "$username";
       $password =  $_POST['password']; echo "$password";
       }
    ?>***
Aleksandr Erokhin
  • 1,904
  • 3
  • 17
  • 32
Rani
  • 1
  • 4

1 Answers1

2

You check $_POST["submit"] submit isset or not in php script. but you don't send from your form.

Try this:

<form action="onlogin.php" method="post">
    <h1>Login Form</h1>
    <div>
        <input type="text" placeholder="Username" required="" name="username" />
    </div>
    <div>
        <input type="password" placeholder="Password" required="" name="password" />
    </div>
    <div>
        <input type="submit" name="submit" value="Log in" />
        <a href="#">Lost your password?</a>
        <a href="signup.html">Register</a>
    </div>
</form>
  • 1
    Using isset to check if submit is set is bad practice. I would suggest using if ($_SERVER['REQUEST_METHOD'] == "POST") –  Nov 13 '16 at 08:47