I am a little confused with what you are trying to do, correct me if I'm wrong but this is what I understand from your question:
You want to add data into a Users table from a form, but you only want to add user which have order an item that does not already exist in the items table?
------ This now confirmed ------
Right well this is how I would go about it.
so you are collecting the data from the form using the POST method.
$_POST['email'] and so on. You want to make sure that the data collected is 100% clean so I use a handly little cleanString function I created...
function cleanString($var)
{
$var = strip_tags($var); //Removes all HTML tags
$var = htmlentities($var); //Converts characters into HTML entities
$var = stripslashes($var); //Removes any backslashes
return mysql_real_escape_string($var); // Escapes all special characters
}
and would use it like this...
$email = cleanString($_POST['email']);
$item = cleanString($_POST['item']);
etc...
with all of your clean data you now want to check if the item exists from the order table. so do a query along these lines:
$query = "SELECT items FROM order WHERE items=".$item;
$result = mysql_query($query);
Then check if a result was found
if(mysql_num_rows($result) > 0)
{
// Result found do not process...
}
else
{
// Result not found, process...
$query = "INSERT INTO user ...";
}
if you are doing multiple inserts in one go you can wrap this all in a while or foreach loop to process it all in one go. although considering it coming from a form I guess you will only have 1 input at a time?
hope this helps.
------- adding a while loop ------
so you are wanting to add multiple records in one go, this entirely depends on how you are collecting the data from the form, to give an exact answer I will need a bit more information about how you are collecting the data from the form. Do you have 3 of each field to add 3 people at once, or are you saving all the data to an array for processing later?
something along these lines will work if you are putting everything into an array
foreach ($array as $user)
{
$item = $user['item']
etc...
$query = "SELECT items FROM order WHERE items=".$item;
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
// Result found do not process...
}
else
{
// Result not found, process...
$query = "INSERT INTO user ...";
}
}
This will take each user one by one, get all the data for that user, check if the item exists and then process if it does not exist.
You can also do it with a while loop, but this way is hard to explain without knowing how you are acquiring the data