hi everyone

i need a help in my php project with mysql database connection. I have a form that contains Fname, lname, contact and my problem is when i press the submit button without filling up the form the query will execute which inserts the blank data to my database.

Recommended Answers

You are going to need to do some "if(empty($something))" checks on your post data. To give you really any more information we would need to acctually see what your code looks like.

Jump to Post

I would just read through some articles on form validation with PHP. For example, here are a couple of decent articles on the topic.

http://buildinternet.com/2008/12/how-to-validate-a-form-complete-with-error-messages-using-php-part-1/
http://phpmaster.com/form-validation-with-php/

Jump to Post

All 5 Replies

You are going to need to do some "if(empty($something))" checks on your post data. To give you really any more information we would need to acctually see what your code looks like.

HI,
What you need to do is,
Just add one condition before calliing to the Command Query or you can use validation funcations.
EG:

if(txt.text=txt2.text=txt3.text == '')
{

}
   ErrorMessage("Insert Value First")

else
{
    Your DB Command
}

------------------------------------------
Hope I am clear and it will work for you.

You check to see if the submit button is used before running the form.
$submit = $_POST[submit]
and then

if(isset($submit)) {
    /* Code to run */
}

Just do a check using if;

if($_POST['firstName'] == "" || $_POST['lastName'] =="")
{
echo "All fields have to be filled";
}
else 
{
//Run the submit code
}

That should work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.