I created a form and added php coding to validate input, connect to database and insert the data into a table. When I click on the "Submit" button without entering any input, I should receive an error message. However, I don't. So, I removed the code to connect to the database and a query to insert input info into a table. Now, I only have the following code to test if it reterns an error message, but it still doesn't give me any message. it just reload when I click on "Submit" button. I assume that "if(isset($_POST['submit'])){... " is not working. or echo statement. But I am so new to php, I don't know what's wrong with my code. Please somone help me!!!

<?php  //input Varidation

if(isset($_POST['submit'])){          //Check if the form has been submitted.
	$message=NULL;
	if(empty($_POST['username'])){        //validate the username.
		$user = FALSE;
		$message .='<p><font font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="red">You forgot to enter your username!</font></p>';
	} else{
		$user = escape_data($_POST['username']);
	}

if(empty($_POST['password'])){         //validate the password.
	$pass = FALSE;
	$message .='<p><font font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="red">You forgot to enter your password!</font></p>';
} else{
	$pass = escape_data($_POST['password']);
}

if(isset($message)){
	echo  $message;
}
}
?>PHP]

After this code, I have a form using html...

    You're new so pare it down more.

    this will detect a form post

    if($_POST){

    }

    and that's all you need

    PHP is case sensitive. Are you sure that you have a button named 'submit' ? Or is it Submit? To PHP there's a difference.

    If there is no form post then $_POST = blank which is the same as false, so use the query method I showed above. No post, stuff inside the {} doesn't get executed.

    Sam

      Thank you so much, sfullman. It worked perfectly!

        Write a Reply...