ladieballer2004 Posted August 24, 2009 Share Posted August 24, 2009 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     Press the Back Button <br/>';} if(empty($LastName)) {echo'<b>You forgot to enter your Last Name     Press the Back Button <br/>';} if(empty($Age)) {echo'<b>You forgot to enter your Age     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     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 More sharing options...
Catfish Posted August 24, 2009 Share Posted August 24, 2009 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     Press the Back Button <br/>'; $dataOK = FALSE; } if(empty($LastName)) { echo'<b>You forgot to enter your Last Name     Press the Back Button <br/>'; $dataOK = FALSE; } if(empty($Age)) { echo'<b>You forgot to enter your Age     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     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 ?> Link to comment https://forums.phpfreaks.com/topic/171600-quick-question-about-validation/#findComment-904894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.