Hey all i am working on a simple registration form and i have done a simple test on it. basically i said if the username filed is empty and we click submit it will echo out 'all filed's are required' else Ok. My code looks fine or else i am going insane can some one have a look for me thank you :)
CODE:
<?php
//require 'core.inc.php';
if(isset($_POST['username'])&& isset($_POST['password']) && isset($_POST['passwordAgain'])&& isset($_POST['Firstname'])&& isset($_POST['Lastname'])){
$username = $_POST['username'];
$password = $_POST['password'];
$password_again = $_POST['passwordAgain'];
$Firstname = $_POST['Firstname'];
$Lastname = $_POST['Lastname'];
if(!empty($username)){
echo 'OK.';
}else{
echo 'fill in all details thank you';
}
}
?>
<form action="join.inc.php" method="POST">
Username: <input type="text" name="username" /><br />
Password: <input type="password" type="password" /><br />
Password Again: <input type="password" type="passwordAgain" /><br />
FirstName: <input type="text" name ="Firstname"/><br />
LastName: <input type="text" name ="Lastname" /><br />
<input type="submit" value="SUBMIT" />
</form>
Rectify this:
Password: <input type="password" name="password" /><br />
Password Again: <input type="password" name="passwordAgain" /><br />
Your problem is in your HTML:
Password: <input type="password" type="password" /><br />
Password Again: <input type="password" type="passwordAgain" /><br />
You are specifying the type field twice instead of the name field.
what about giving a name for the submit button and try like this:
<input type="submit" name="sbmtBtn" value="SUBMIT" />
and submit part as:
if(isset($_POST['sbmtBtn']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$password_again = $_POST['passwordAgain'];
$Firstname = $_POST['Firstname'];
$Lastname = $_POST['Lastname'];
if($username && $password && $password_again && $Firstname && $Lastname))
{
echo 'OK.';
}
else
{
echo 'all fields are required.';
}
}