form validation

Help Please. I have a program that I’m needing to verify my form data is correct before inserting it in mysql db. can you help

Can you please post the code you currently have, and describe exactly what you need it to do?

Here is my form code but it is only for the entry of data as I have not progressed to the validation stage:

<title>Add Homeowner</title>
Last Name:
First Name:
Spouse:
Home Phone:
Address:
Cell Phone:
Spouse Cell:
E-mail:
Spouse Email:
Birthday:
Spouse Birthday:
Anniversary:
Children:
Pets (enter name,breed,color):
Misc Information:
Website:

Thanks

What do you mean by verify the data is correct? do you mean if it is set?
If so, here is an example:

[php]<?php
if (isset($_POST[‘submit’]))
{
if (empty($_POST[‘Last_Name’]) || empty($_POST[‘First_Name’]) || empty($_POST[‘Spouse’]))
{
if (empty($_POST[‘Last_Name’]))
{
echo “Please enter a last name!
”;
}
if (empty($_POST[‘First_Name’]))
{
echo “Please enter a first name!
”;
}
if (empty($_POST[‘Spouse’]))
{
echo “Please enter a spouse!
”;
}
}
else
{
echo “fields are set”;
}
}
?>[/php]

Thanks for the information, I am relative new at PHP and don’t know all the tricks and have read many tutorials but found they covered only what I already knew. Is there a php tutorial wiki?
Thanks again

Personally I taught myself php just by messing around but this comes in handy when i need help:
W3Schools have a PHP section.

Apparently I know less than I thought. I put the code in at the top of my php code thus:

<?php if (isset($_POST['submit'])) { if (empty($_POST['Last_Name']) || empty($_POST['First_Name']) || empty($_POST['Address']) || empty($_POST['email'])) { if (empty($_POST['Last_Name'])) { echo "Please enter a last name!
"; } if (empty($_POST['First_Name'])) { echo "Please enter a first name!
"; } if (empty($_POST['Spouse'])) { echo "Please enter a Address!
"; } if (empty($_POST['Spouse'])) { echo "Please enter a email!
"; } } else { echo "Required fields are set"; } } $sql="INSERT INTO homeowners (Last_Name,First_Name,Spouse,Address,Birthday,Spouse_Birthday,Anniversary,Web_Site,Home_Phone,email,Spouse_email, Cell_Phone,Spouse_Cell,Children,Pets,Misc) VALUES ('$_POST[Last_Name]','$_POST[First_Name]','$_POST[Spouse]','$_POST[Address]','$_POST[Birthday]','$_POST[Spouse_Birthday]','$_POST[Anniversary]', '$_POST[Web_Site]','$_POST[Home_Phone]','$_POST[email]','$_POST[Spouse_email]','$_POST[Cell_Phone]','$_POST[Spouse_Cell]', '$_POST[Children]','$_POST[Pets]','$_POST[Misc]')"; Kept the echo in the else just for safety but apparently didn't work as it still said record inserted, of course they were all fields blank. So does it go in the html file for the form using php) or in the php code for the inserg? As a side note I do got to w3schools quite often but must have missed this code.

Thanks for all your help. I finally got it working.

Sponsor our Newsletter | Privacy Policy | Terms of Service