0

I have a WAMP server setup and I have the following form in file login.php

<form action="login.php" method="post">
  Username: <input type="text" id="loginUsername" />
  Password: <input type="password" id="loginPassword" />
  <input type="submit" value="Log-in" id="login" />
</form>

And in the same file I have this PHP:

if(isset($_POST))
{
    print "post is set";
    print_r($_POST);
}

However the print_r() never displays any of the field's values. I have tried using the get method in the form too.

Is this something to do with hosting on WAMP?

2 Answers 2

2

You forgot the name attributes for your form elements. Without it those values will not be submitted.

<form action="login.php" method="post">
  Username: <input type="text" name="loginUsername" id="loginUsername" />
  Password: <input type="password" name="loginPassword" id="loginPassword" />
  <input type="submit" value="Log-in" id="login" /></p>
</form>
Sign up to request clarification or add additional context in comments.

Comments

0

you must provide name attribute for the input element so that they can be available in the global variable $_GET ,$_POST or $_REQUEST. Remember id or class ,etc are for javascript/jquery/css processing and name attribute are server side processing (php ,jsp ,etc)

<form action="login.php" method="post">
    <label for="username">Username:</label><input type="text" name="username" id="username" />
    <label for="password">Password:</label> <input type="password" name ="password"id="password" />
    <input type="submit" value="Log-in" id="login" />
</form>

hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.