Reputation: 3079
My HTML code:
<form class="well" name="login" action="text.php" method="post" >
<input type="text" class="span3" id="username" name"username" placeholder="Enter your valid email">
<input type="text" class="span3" id="password" name"password" placeholder="Enter your password">
<button type="submit" class="btn" >Enzemble </button>
</form>
<h2>New User? ... Register</h2>
<form class="well" name="register" action="register.php" method="post" >
<input type="text" class="span3" id="email" name="email" placeholder="Enter your valid email" onBlur="emailValidation()">
<button type="submit" class="btn">Enter Enzemble!</button>
</form>
The bottom form works fine.
The top code gives "undefined index" notice and does not read values of username and password in text.php The text.php code:
<?php
if (isset($email)) $email=$_POST["username"];
if (isset($password)) $password=$_POST["pasword"];
echo "username " . $email . "password " . $password;
?>
The error: Notice: Undefined index: pasword in /home/nitin/www/enzemble/text.php on line 8 Notice: Undefined variable: email in /home/nitin/www/enzemble/text.php on line 9 username password
I am not getting html form values in php. This is surprising. I am working on it for a long time. Please help.
Upvotes: 0
Views: 217
Reputation: 91942
You have a syntax error in your HTML code. It's missing a =
for the name
attribute of the input fields:
<input type="text" class="span3" id="username" name"username" placeholder="Enter your valid email">
HERE ----------------------------------------------^
Upvotes: 0
Reputation: 14502
That's because you wrote pasword
instead of password
. Try it with
if (isset($password)) $password=$_POST["password"];
Anyway, you should check for $_POST['password']
instead just for $password
See register_globals:
This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
Upvotes: 4
Reputation: 10074
Because it's wrapped in another <form></form>
wrap everything in one form.
Like:
<form class="well" name="register" action="register.php" method="post" >
<input type="text" class="span3" id="email" name="email" placeholder="Enter your valid email" onBlur="emailValidation()" />
<input type="text" class="span3" id="username" name="username" placeholder="Enter your valid email" />
<input type="text" class="span3" id="password" name="password" placeholder="Enter your password" />
<button type="submit" class="btn">Enter Enzemble!</button>
</form>
Edit: And update php script like Emil suggested
Upvotes: 0
Reputation: 91942
You are just checking if the variables $email
and $password
are set, but they aren't set yet, right? So either you meant to negate your checks:
if (!isset($email)) $email=$_POST["username"];
if (!isset($password)) $password=$_POST["password"];
Or you meant to check that the $_POST fields were set:
if (isset($_POST['email'])) $email=$_POST["username"];
if (isset($_POST['password'])) $password=$_POST["password"];
Upvotes: 2
Reputation: 1055
if (isset($password)) $password=$_POST["pasword"];
You're spelling password in $_POST["pasword"]
with just one s.
Upvotes: 0
Reputation:
$password not exists yet, check $_POST["pasword"] in isset
, not $password.
Upvotes: 0