Welcome Guest ( Log In | Register )




                Web Hosting

 
Reply to this topicNew Topic
How To Validate The Login Form Using Php Pcre, PHP Validation is on Server Side and Java Script on Client Side.
veerumits
post Oct 23 2008, 09:40 PM
Post #1


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 38
Joined: 23-October 08
From: India
Member No.: 34,049
myCENTs:27.89


I am Design a Sample Login form Using This Code :

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.
Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts 8 priteshgupta 640 Yesterday, 03:55 PM
Last post by: yordan
No New Posts   8 Grafitti 16,030 2nd January 2009 - 08:45 AM
Last post by: Guest
No New Posts   2 magiccode9 99 18th December 2008 - 06:56 PM
Last post by: khalilov
No New Posts 6 miCRoSCoPiC^eaRthLinG 1,993 29th November 2008 - 02:24 PM
Last post by: yordan
No New Posts   11 mastercomputers 2,395 10th November 2008 - 08:22 PM
Last post by: Quatrux
No New Posts   15 coder2000 6,335 7th November 2008 - 03:44 PM
Last post by: Shag
No New Posts   0 FirefoxRocks 217 6th November 2008 - 01:58 AM
Last post by: FirefoxRocks
No New Posts   3 magiccode9 323 1st November 2008 - 05:53 PM
Last post by: faulty.lee
No New Posts   10 cool 1,524 20th September 2008 - 12:49 AM
Last post by: sparkx
No New Posts   0 saint-michael 341 9th September 2008 - 12:38 AM
Last post by: saint-michael
No New Posts   0 saint-michael 298 30th August 2008 - 11:43 PM
Last post by: saint-michael
No New Posts   5 Daniel666 1,711 31st July 2008 - 05:07 AM
Last post by: Habble
No New Posts   8 thenumberone 1,125 25th July 2008 - 04:16 AM
Last post by: Mike gambino
No New Posts
4 PHP
12 Houdini 3,287 20th July 2008 - 02:33 AM
Last post by: Guest
No New Posts   3 Mordent 530 19th July 2008 - 11:55 PM
Last post by: Arbitrary