Help with validation

Discussion in 'PHP' started by ladieballer2004, Aug 24, 2009.

  1. #1
    So i have created validation criteria for my web form. I have tested it to see if it catches the errors on the form. And it does. Is there an easy way to make the parser stay on the validation code until evrything is found correct.

    the beginning of my web form:
    <form method="POST" action="insert.php">

    My validation code is on insert.php I tried this:
    
    if (isset($_POST['Submit']))
    {
    //Declaring the text input fields
    $ULVID= $_POST['ULVID'];
    $FirstName= $_POST['FirstName'];
    $LastName= $_POST['LastName'];
    $Age= $_POST['Age'];
    
    // Checking to see if the required fields are empty
    if(empty($FirstName))
    {echo'<b>You forgot to enter your First Name &nbsp &nbsp Press the Back Button <br/>';}
    if(empty($LastName))
    {echo'<b>You forgot to enter your Last Name &nbsp &nbsp Press the Back Button <br/>';}
    if(empty($Age))
    {echo'<b>You forgot to enter your Age &nbsp &nbsp Press the Back Button <br/>';}
    if(
    		strpos($Email, '@') === false ||
    		strpos($Email, '.') === false ||
    		strpos($Email, ' ') != false ||
    		strpos($Email, '@') > strpos($Email, '.')
    	)
    	{echo '<b>Please enter a valid email address &nbsp &nbsp Press the Back Button <br/>';}
    
     nl2br(strip_tags(stripslashes($Answer1)));
     nl2br(strip_tags(stripslashes($Answer2)));
    }
    else
    {
     
    	$con = mysql_connect("localhost","","");
    
    
    	mysql_select_db("CpaApp", $con);
    
    //insert Queries
    
    Code (markup):
    Please Help
     
    ladieballer2004, Aug 24, 2009 IP
  2. Dollar

    Dollar Active Member

    Messages:
    2,598
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Just some advice just checking for @ in a email address is not proper validation. Someone could submit literally.
    fake*(#*(email@example.com , and that would be "valid".​
    You'll want to use preg_match for the email validation and a good regex.
    Which you should find already done somewhere, no point reinventing the wheel.
     
    Dollar, Aug 24, 2009 IP
  3. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #3
    There are three ways to do that:

    1. Use JavaScript also to validate. Form submissions should be validated on the server side also.

    2. Use Ajax and do the validations on the server side only.

    3. Use Session Variables to keep the values in the form.(when the form is displayed next time)
     
    prasanthmj, Aug 24, 2009 IP