compare multpile (optional) inputs against [solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

compare multpile (optional) inputs against [solved]

Post by lafflin »

Hello, I am trying to check submitted form data (cell phone, home phone, other phone) against the records in my DB to prevent duplicate records.
I am using these fields as one of several ways to identify a user that has already registered in the past.
But my code dictates that the user must fill out atleast one of these fields the other two can be left blank if so desired. The user can pick which of these fields they want to fill.
That leaves two of them possily empty.

If in my query I were to write the code

Code: Select all

$query0 = "SELECT 
	                   pid,
			   FROM    
			           parent_info 
			  WHERE 
			           (street_address = '$street')
			  OR        
			            (h_phone or c_phone or o_phone) = ('$h_phone' or '$c_phone' or '$o_phone')
			  OR
			               (email = '$email')" ;
then every record without all three phone numbers will match any user who does not fill out all three fields.

Again, this query is to validate that the user has not previously registered, so it's obviously not going to work.

How can I check to make sure that every number entered into my DB is Unique.

In typing this question I think that I have thought of a solution. If it works I will post it, but also, I am a beginner and my hunch is that
this is a common issue and many of you may know a more standard and concise way of woring this out than what I am about to attempt.

Thanks
Last edited by lafflin on Wed Sep 19, 2007 1:51 pm, edited 1 time in total.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post by lafflin »

Nope, I'm a bit lost. That's not how ya write that query.
here's what I have done.....I am aware that this might be amusing.

Code: Select all

if (!empty($h_phone)) { $ph1 ="$h_phone";}
 else {$ph1=ooo;} 
if (!empty($c_phone)) { $ph2 ="$c_phone";} 
else {$ph2=ooo;}
if (!empty($o_phone)) { $ph3 ="$o_phone";}
else {$ph3=ooo;} 

	
	$query0 = "SELECT 
	                   pid,
			   FROM    
			           parent_info 
			  WHERE 
			           (street_address = '$street')
			  OR        
			            (home_phone or cell_phone or other_phone) = ('$ph1' or '$ph3' or '$ph2')
			  OR
			               (email = '$em')" ;
						   
	$result0 = mysql_query ($query0) or die($query0);
			if (mysql_num_rows($result0)>0) {
		echo 'Our records show that you are already registered!';
		exit() ;
		} else{
I am just getting the query read back to me from the die, here's what it reads:

SELECT pid, FROM parent_info WHERE (street_address = 'streetaddress1') OR (home_phone or cell_phone or other_phone) = ('999999' or '999999' or '999999') OR (email = 'xxxxxxxx@gmail.com')

I also tried putting another set of barackets around the (home_phone.....)=('99999...)
to make it:
((home_phone.....)=('99999...)).
That's when I realized that I'm not playing by the rules.
Any help is greatly appreciated.
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post by lafflin »

Stupid Comma!

AHH!!!!!!!!!!!!
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

Code: Select all

mysql_query ($query0) or die(mysql_error()."[sql:$query0]");
would be better for debugging in the future
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post by lafflin »

Thanks, that'll be a useful tidbit instead of having to copy and past into phpmyadmin!
Post Reply