pioneerx01 Posted January 7, 2011 Share Posted January 7, 2011 Ok, I am not sure if I can explain it correctly, but here it goes. I have a form where user is asked to enter up to three name. Let's say that the fields are called [name1], [name2] and [name3] and they are called the came in the table. Now I have a code which allows me to compare what names are in the database versus the name that was entered by the user. $query = "SELECT * FROM Project_Registrations WHERE name1= '$_POST[name1]' "; $result2 = mysql_query($query); if (mysql_numrows($result2) > 0) { while($row = mysql_fetch_array($result2)) {echo" ...error code... ";} } else { ...ok code... }; This works well for one name field but I have three in the form and three in the table. How do I define it so all three name fields in the form are compared to all three in the table and if just on matches I can give them the ...error code...? Oh, and they can enter up to three names in the form, but it could be two or one. Can I code it such: $query = "SELECT * FROM Project_Registrations WHERE name1= '$_POST[name1]' OR name1= '$_POST[name2] OR name1= '$_POST[name2]' OR ...'"; Thanks Quote Link to comment Share on other sites More sharing options...
Zurev Posted January 7, 2011 Share Posted January 7, 2011 Use the IN clause in my opinion. $QUERY = "SELECT * FROM Project_Registrations WHERE name1 IN('value1', 'value2', 'value3')"; More on that: http://www.w3schools.com/sql/sql_in.asp Quote Link to comment Share on other sites More sharing options...
pioneerx01 Posted January 7, 2011 Author Share Posted January 7, 2011 So in the entire array I can do this?: $QUERY = "SELECT * FROM Project_Registrations WHERE name1 IN('value1', 'value2', 'value3') OR name2 IN('value1', 'value2', 'value3') OR name3 IN('value1', 'value2', 'value3')"; Quote Link to comment Share on other sites More sharing options...
pioneerx01 Posted January 7, 2011 Author Share Posted January 7, 2011 Ok, I got it working. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.