Jump to content

Custom: "SELECT * FROM * WHERE ..." statement


pioneerx01

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.