Validation error, always shows error even when complete


#1

Hi all, I have a script on a form that should prompt the user to enter all the details required (if they’re blank) however the script seems to run the validation error even through the form button hasnt been processed… here’s a small section of my code.

  if (isset($_POST["form_submit"])) 
			{ 
			$name 					= $_POST['name'];
			$notes 					= $_POST['notes'];
			$updated 				= $_POST['updated'];
			$updatedby 				= $_POST['updatedby'];
			


		}
		
      if (empty($name)) { 
		echo "<div class='alert alert-success alert-dismissible' role='alert'>
		<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span></button>
		<strong>Error!</strong> Name is missing.
		</div>";
 
	
	} else {
   			
		$sql = "UPDATE suppliers SET 

Any ideas where I’m going wrong? Everything else works and the script updates the database correctly, its just the error message shows before the user has entered any details

Thanks in advance


#2

You want to check for the request type. So,

if($_SERVER['REQUEST_METHOD'] == 'POST') {
// the form was submitted do your processing
}

#3

thanks astonecipher - you’ve got it spot on as usual. Thanks for your help