Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem with sign up script
Old 04-12-2009, 04:56 PM Problem with sign up script
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
I have a script that allows users to become a member of my website, and this piece of code is used to check that there isn't already a user registered in the database with the same email address:

PHP Code:
// check that duplicate email does not exist in tblUser
    
$sql mysql_query ("SELECT userEmail FROM tblUser
                         WHERE userEmail = '
$userEmail'");

    if (
$sql) {
        
$error[] = 'userEmailDup';
      } 
The thing is, no matter what email address I type in, even if there is not duplicate in the database... it still produces an error!

I assume that the problem has to be in the code above, am I right?
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 04-12-2009, 07:30 PM Re: Problem with sign up script
Novice Talker

Posts: 5
Trades: 0
Try something like:

Code:
// check that duplicate email does not exist in tblUser
$sql = mysql_query ("SELECT userEmail FROM tblUser WHERE userEmail = '$userEmail' LIMIT 0,1");
$sql_count = mysql_num_rows($sql);

// If Email exists, produce an error.
if ($sql_count == 1) {
        $error[] = 'userEmailDup';
}
Sarvar is offline
Reply With Quote
View Public Profile
 
Old 04-12-2009, 08:02 PM Re: Problem with sign up script
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The problem is that your query is successful, so if($sql) always returns true even if your query returns an empty result. Use COUNT.

PHP Code:
$result mysql_query("SELECT COUNT(*) FROM tblUser WHERE userEmail = '$userEmail';");
$count mysql_fetch_array($resultMYSQL_NUM);
$count $count[0];

if(
$count 0)
{
     
$error[] = 'userEmailDup';

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-12-2009 at 08:05 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-13-2009, 04:41 AM Re: Problem with sign up script
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Ahhh thanks!
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Reply     « Reply to Problem with sign up script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34064 seconds with 12 queries