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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.