-3

Why does Username work and password not? its spose to spit out what you type in the text boxes. Username works but password gives me an error.

 <form method = "POST">

    Username:<input type='text' name="username"><br>
    Password: <input type = 'password' name = "password"><br>
    <input type = 'submit' value = 'Login' name= 'submit'>




    <?php



    $Ausername = "Adam";
    $Apassword = "abc";

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

    echo $username;
    echo $password;

    ?>

    </form>
2
  • Why do you wrap your $_POST variables in parenthesis?
    – John Conde
    Jan 20, 2014 at 1:53
  • I thought you had to it makes no difference tho. Jan 20, 2014 at 1:54

1 Answer 1

3

You're omitting a "=" following the name.

Should be:

  Password: <input type = 'password' name="password">

This works. If it doesn't work for you, I don't know what to say.

<form method="POST">
    Username: <input type='text' name="username"><br>
    Password: <input type='password' name="pw"><br>
    <input type='submit' value='Login' name='submit'>
</form>

<?php
$username = $_POST['username'];
$password = $_POST['pw'];

echo $username;
echo $password;

?>
6
  • You have name "password" when it needs to be name="password". As is, you're currently not setting the name to anything.
    – emsoff
    Jan 20, 2014 at 1:56
  • Still arnt working :( Jan 20, 2014 at 1:57
  • You are echoing unset values. Check to make sure they are actually set. Jan 20, 2014 at 1:57
  • What do you mean they get set? Jan 20, 2014 at 2:00
  • Copy and paste my updated answer into your code. It works. There's no way it does not work.
    – emsoff
    Jan 20, 2014 at 2:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.