CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Check if value exist in mysql (http://www.codingforums.com/showthread.php?t=286727)

zubat 01-30-2013 12:17 PM

Check if value exist in mysql
 
PHP Code:

$sql mysql_query("SELECT email FROM users WHERE email ='$email'");
                                    
if(
mysql_num_rows($sql) != 0)
{
echo 
'<font color="ff0000"><li> Email exist!</font>';


So my problem is, that even if i write an email that i know exist in the database it let me through. I got the config.php include a bit up in the code so the database connection is no problem.

//Zubat

AndrewGSW 01-30-2013 12:37 PM

mysql_num_rows returns the number of rows or false. The docs. So you should test against > 0.

NB
The mysql library is deprecated - there is a stark warning against its use on the docs page - and will be removed in the future.
The font tag is obsolete.
Your LI tag is not closed properly, so your HTML is mal-formed.

TFlan 01-30-2013 02:55 PM

A better way:

PHP Code:

is_resource($q); 

$q being the results from the query


All times are GMT +1. The time now is 09:38 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.