I am new to php and I donβt quite understand why this form is submitted under any circumstances ... So my question is:
How can I fix this, so the form is only submitted when the user fills in all the fields?
if (!$_POST['username'] && !$_POST['password'] && !$_POST['repassword'] && !$_POST['user_firstname'] && !$_POST['user_lastname'] ){ header('Location: register.php?msg=You did not complete all of the required fields'); }
I used the operators && and || However, it always represents, no matter what field you fill in.
<form action="createuser.php" method="post" name="registration_form" id="registration_form"> <label>Email</label> <input name="username" type="text" id="username" size="50" maxlength="50" /><br /> <label>First Name</label> <input name="user_firstname" type="text" id="user_firstname" size="50" maxlength="50" /><br /> <label>Last Name</label> <input name="user_lastname" type="text" id="user_lastname" size="50" maxlength="50" /><br /> <label>Password</label> <input name="password" type="password" id="password" size="50" maxlength="100" /><br /> <label>Re-type Password</label> <input name="repassword" type="password" id="repassword" size="50" maxlength="100" /><br /> <input type="submit" value="Register" name="submit" />
Thanks in advance for any help, and it looks like a terrific community to be involved!
source share