Honesty Rocks! truth rules.

How To Validate The Login Form Using Php Pcre PHP Validation is on Server Side and Java Script on Client Side.

HOME      >>       Programming

veerumits

I am Design a Sample Login form Using This Code :

 

<?php if(!isset($_POST["OK"])){if(empty($_POST["fname"])){$fnmerror='Invalid First Name';}elseif(empty($_POST["lname"])){$lnmerror='Invalid Last Name';}elseif(empty($_POST["age"])){$ageerror='Invalid Age';}elseif(empty($_POST["city"])){$cityerror='Invalid City';}elseif(empty($_POST["pin"])){$pinerror='Invalid Pin No.';}elseif(empty($_POST["mob"])){$moberror='Invalid Mobile No.';}elseif(empty($_POST["email"])){$emailerror='Invalid Email address';}else{$result =" Thanks submitting your Information";}}?><body bgcolor="#99CC66" text="#663333" link="#FFFF00" alink="#996666" vlink="#FF6666"><center> <form action="Student.php" method="post"> <H1><font color="#800000">Please Fill The Following information :</font></H1> <font color="#800000"><br> </font> <TABLE BORDER="" BGCOLOR="yellow" width="448" height="293"> <TD height="2" width="86"> <TR> <TD width="86" height="35"><font size="+1" color="#800000">First Name</font></TD> <TD width="41" height="35"><font color="#800000">:</font></TD> <TD width="299" height="35"> <font color="#800000"> <input type="text" name="fname" value="<?php echo $_POST["fname"]; ?>"/> <b> <?php echo '<font color="RED">'.$fnmerror.'</font>'; ?> </b> </font></TD> </TR> <TR> <TD width="86"><font size="+1" color="#800000">Last Name</font></TD> <TD width="41"><font color="#800000">:</font></TD> <TD width="299"> <font color="#800000"> <input type="text" name="lname" value="<?php echo $_POST["lname"]; ?>" /> <b> <?php echo '<font color="RED">'.$lnmerror.'</font>'; ?> </b> </font></TD> </TR> <TR> <TD width="86"><font size="+1" color="#800000">Age</font></TD> <TD width="41"><font color="#800000">:</font></TD> <TD width="299"> <font color="#800000"> <input type="text" name="age" value="<?php echo $_POST["age"]; ?>" /> <b> <?php echo '<font color="RED">'.$ageerror.'</font>'; ?> </b> </font></TD> </TR> <TR> <TD width="86"><font size="+1" color="#800000">City</font></TD> <TD width="41"><font color="#800000">:</font></TD> <TD width="299"> <font color="#800000"> <input type="text" name="city" value="<?php echo $_POST["city"]; ?>" /> <b> <?php echo '<font color="RED">'.$cityerror.'</font>'; ?> </b> </font></TD> </TR> <TR> <TD width="86"><font size="+1" color="#800000">Pin No.</font></TD> <TD width="41"><font color="#800000">:</font></TD> <TD width="299"> <font color="#800000"> <input type="text" name="pin" value="<?php echo $_POST["pin"]; ?>" /> <b> <?php echo '<font color="RED">'.$pinerror.'</font>'; ?> </b> </font></TD> </TR> <TR> <TD width="86"><font size="+1" color="#800000">Mobile</font></TD> <TD width="41"><font color="#800000">:</font></TD> <TD width="299"> <font color="#800000"> <input type="text" name="mob" value="<?php echo $_POST["mob"]; ?>" /> <b> <?php echo '<font color="RED">'.$moberror.'</font>'; ?> </b> </font></TD> </TR> <TR> <TD height="28" width="86"><font size="+1" color="#800000">Email</font></TD> <TD height="28" width="41"><font color="#800000">:</font></TD> <TD height="28" width="299"> <font color="#800000"> <input type="text" name="email" value="<?php echo $_POST["email"]; ?>" /> <b> <?php echo '<font color="RED">'.$emailerror.'</font>'; ?> </b> </font></TD> </TR> <TR SIZE="100"> <TD colspan="3" height="7"><font color="#800000"> <b> <input type="Button" size="40" name="result" value =" <?php echo $result; ?> " /> </b> </font></TD> </TR> <TR> <TD width="86" height="3"><font color="#800000">.</font></TD> <TD width="41" height="3"> <font color="#800000"> <input type="Submit" value="OK" /> </font></TD> <TD width="299" height="3"><font color="#800000">.</font></TD> </TR> </TABLE> </form></center>

When i brows on Server i see This

here i am not able to show you exactly but just like this

Please Fill The Following information :

 

 

First Name : Invalid First Name

Last Name :

Age :

City :

Pin No. :

Mobile :

Email :

 

(OK)

 

 

 

Conclusion:

 

In starting Invalid First Name even i am not hitting on OK button but when i hit it is fine i want that it come only when i hit on ok button and field are blank.

any one correct this problem what is right code for this

 

i think that in this code have error

 

<?php

if(!isset($_POST["OK"]))

{

 

}

?>

 

 

but i am get resolve after so many try.