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
https://forums.phpfreaks.com/topic/223653-custom-select-from-where-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.