I have a form which allows a backend manager to enter up to 3 email addresses into a simple mySQL table (which has just 2 fields- ID, which is an auto-incrementing primary key, and the Email address field, just a Varchar)
The problem is that as it stands, if they enter just one email address and leave the other two form fields empty, empty values get inserted as new records in the table.
This is the script:
I tried setting different queries based on whether or not the various variables were empty, using if empty and if !empty, but that didn't work.
// Grab the data from the first Add a New Email form and assign to variables
$emailaddress = $_POST['_EmailAddress'];
$emailaddress2 = $_POST['_EmailAddress2'];
$emailaddress3 = $_POST['_EmailAddress3'];
// Build SQL Query
$query = "INSERT INTO emailcontacts (Email) VALUES ('$emailaddress'), ('$emailaddress2'), ('$emailaddress3')"; // specify the table and field names for the SQL query
if($result = mysql_query($query))
//go to the new member confirmation page
echo "ERROR: ".mysql_error();
What I want is for it to just enter new records for when the various form fields and coresponding variables have actual values.
I can't really force the user to enter three new email addresses each time as they may not have that many to add.