Jump to content
Killersites Forums

vijay587

New Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by vijay587

  1. 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>

×
×
  • Create New...