Jump to content

Archived

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

eastcoastdubs

2 fields dont match but both are in DB, what do i do?

Recommended Posts

I have a userid and email field and I have a function checking if both are in the database first and to give the correct error message if they are not. BUT hypothetically speaking. Say someone putd a username and email address that are both in the database BUT they are not in the same record. I tried doing this and I got a blank screen. The query goes thru correctly since the error messages I have just check to see if they are in the database. BUT there is no error stoping saying they are not in the same record since the email and userid do not match.

 

Should I use a third function checking both field and saying that the combination email and userid do not match?

 

I use this to get the fields for my mail() function

 

$sql = \"SELECT userid, userpassword, username, useremail FROM $user_tablename WHERE userid = \'$userid\' AND useremail = \'$email\'\";

Share this post


Link to post
Share on other sites

$sql = \"SELECT userid, userpassword, username, useremail FROM $user_tablename WHERE userid = \'$userid\' OR useremail = \'$email\'\";

 

If you get 1 row - same person

2 rows - userid allready taken, email allready taken - by different persons.

This is only valid IF you check for a unique userid, i.e. that you don\'t allow two persons to have the same userid (which I assume you do).

 

Reading your post again, I think you want to check that a given userid and email match the SAME RECORD ?

 

Then your original solution is the correct one:

$sql = \"SELECT userid, userpassword, username, useremail FROM $user_tablename WHERE userid = \'$userid\' AND useremail = \'$email\'\";

 

This returns only one row, if the submitted userid and email are in the same record, if NOT it will return zero rows!

 

P.

Share this post


Link to post
Share on other sites

×

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.