knobby2k Posted September 1, 2011 Share Posted September 1, 2011 Hi guys, I am going nuts with this! It HAS to be something dead simple but I can't seem to see what is staring me in the face. Basically I have made a registration form and when complete you are emailed a link to click on. When you click on the link you go to a new page. The page takes the email address and the verification code from the URL via _GET. The database is then queried for a match of the email address AND the verification code, if there is a relevant record then success is displayed otherwise unsuccessful is displayed. Code: $email = strip_tags(htmlentities($_GET['email'])); $code = strip_tags(htmlentities($_GET['code'])); // confirm the variables hold the correct data echo "email: $email and code: $code"; $query = "SELECT * from userdb WHERE email='$email' AND code ='$code'"; if (mysql_query($query)) { echo "success"; } else { echo "unsuccessful"; } My problem is this query is always returning 'success'... even when the code and/or email does not match what is in my database? What am i missing? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/246194-going-insane-with-something-simple/ Share on other sites More sharing options...
jcbones Posted September 1, 2011 Share Posted September 1, 2011 You should be checking mysql_num_rows(), as even an unsuccessful (returned 0 rows) query will return a result resource. Quote Link to comment https://forums.phpfreaks.com/topic/246194-going-insane-with-something-simple/#findComment-1264413 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2011 Share Posted September 1, 2011 if (mysql_query($query)) ^^^ That's testing if the query executed without any ERRORS (i.e. a connection problem, a syntax error, a miss typed table/column name.) That doesn't test if the query matched any rows or not. See - mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/246194-going-insane-with-something-simple/#findComment-1264414 Share on other sites More sharing options...
knobby2k Posted September 1, 2011 Author Share Posted September 1, 2011 Excellent, i'll give that a go. Cheers lads Quote Link to comment https://forums.phpfreaks.com/topic/246194-going-insane-with-something-simple/#findComment-1264487 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.