Jump to content

Quick Question about validation


ladieballer2004

Recommended Posts

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

Please Help

 

Link to comment
https://forums.phpfreaks.com/topic/171600-quick-question-about-validation/
Share on other sites

Here's one way to do it, if I am understanding what you want to do correctly:

 

<?php
if (isset($_POST['Submit']))
{
//Declaring the text input fields
$ULVID= $_POST['ULVID'];
$FirstName= $_POST['FirstName'];
$LastName= $_POST['LastName'];
$Age= $_POST['Age'];

$dataOK = TRUE;

// 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/>';
$dataOK = FALSE;
}
if(empty($LastName))
{
echo'<b>You forgot to enter your Last Name &nbsp &nbsp Press the Back Button <br/>';
$dataOK = FALSE;
}
if(empty($Age))
{
echo'<b>You forgot to enter your Age &nbsp &nbsp Press the Back Button <br/>';
$dataOK = FALSE;
}
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/>';
      $dataOK = FALSE;
   }

nl2br(strip_tags(stripslashes($Answer1)));
nl2br(strip_tags(stripslashes($Answer2)));
}
if ($dataOK)
{

   $con = mysql_connect("localhost","","");


   mysql_select_db("CpaApp", $con);

//insert Queries
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.