vijay587 Posted August 4, 2012 Report Share Posted August 4, 2012 suppose I have 3 form fields Firstname, lastname and username and I want to check these fields using PHP. whenever I checked field is empty or does not meet any requirement then form displays error against to every field. please guide me exact program that error only display to those field which does not meet requirement. please go through my code:- <?php $firstname=$_POST['Fname']; $lastname=$_POST['Lname']; $Username=$_POST['Username']; $err=""; if(isset($submit)){ if($firstname==""){ $err = "<i style='color:red'>Please enter your first name!</i>"; }else{ if(!$firstname==preg_match("/^[a-zA-Z]{3,20}$/",$firstname)){ $err = "<i style='color:red'>please enter your correct name!</i>"; }else{ $err = ""; if($lastname==""){ $err = "<i style='color:red'>Please enter you last name!</i>"; }else{ if(!$lastname==preg_match("/^[a-zA-Z]{3,20}$/",$lastname)){ $err = "<i style='color:red'>please enter your correct name!</i>"; }else{ if($Username==""){ $err = "<i style='color:red'>please enter your new username!</i>"; }else{ if(!$Username==preg_match("/^[a-zA-Z0-9].*{?=.*\w}.*{5,20}$/",$Username)){ $err = "<i style='color:red'>incorrect username!</i>"; } } } } } } ?> <table border="1" cellpadding="0" cellspacing="0"> <tr><td align="right">First name:</td> <td><form name="test" action="samefile.php" method="post"><input type="text" name="Fname"></td><td><?php echo $err; ?></td> </tr> <tr> <td align="right">Last name:</td> <td><input type="text" name="Lname"></td> <td><?php echo $err; ?></td> </tr> <tr> <td align="right">Username:</td> <td><input type="text" name="Username"></td> <td><?php echo $err; ?></td> </tr></form></table> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 5, 2012 Report Share Posted August 5, 2012 Currently, what is wrong with your current code? How isn't it working? Are you getting error messages? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.