Query for existing users and emails

02-20-04, 04:24 PM
|
 |
Aspiring Coder
|
|
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Query for existing users and emails
I am setting up a form to let people join a site. The script checks for missing form fields, sees if the username and email are already used, and inserts the new members data into a table. The following script works, including the missing form data and the insert, except that it isn't giving the error message when a username or email address is already being used. It simply adds the data into the table. I've seen this type of usage before in other scripts, but apparently I added it here incorrectly. Any suggestions?
Heres the script....
|

02-20-04, 04:55 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by mdhall
The following script works, including the missing form data and the insert, except that it isn't giving the error message when a username or email address is already being used.
|
Instead of getting all users from the database, you could try something like this:
That way you only need to see if the number that is returned is >0 - if so, then you know there is an existing username.
The same thing can be done with the email. It could also be arranged like:
That would check for either a username conflict or an email conflict. If Count>0 then send visitor to generic error page.
|

02-20-04, 05:09 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is some code that might help you out:
|

02-20-04, 05:18 PM
|
 |
Aspiring Coder
|
|
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
|
|
I tried this, and It still does the same thing, i.e., add the info even though its already taken.
$combined_check = mysql_fetch_assoc(mysql_query("select count(*) as Count from users where
user='$user' or email='$email'"));
if ($combined_check["Count"]>0) {
echo "That username or password is in use";
quit;
}
I have had trouble getting sessions to work on members-type pages I set up. Basically, I want a system for viewers to become members of a site, so that only members can post material, however anyone can view what is there already. If you have any suggestions or sample scripts I could try out, I would really appreciate it.
Last edited by mdhall; 02-20-04 at 05:21 PM.
|

02-20-04, 05:21 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can you edit your previous post to reflect that latest code changes that you made ?
|

02-20-04, 05:24 PM
|
 |
Aspiring Coder
|
|
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Quote:
|
Originally Posted by YourPHPPro
Can you edit your previous post to reflect that latest code changes that you made ?
|
Heres the full code i tried...
|

02-21-04, 12:45 PM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
hmm ..
why are you using quit; ? and what is it exactly?
what I know is die; and exit; are the ones that terminate script execution!!
anyway, I suggest that you use the or die() part in your mysql_query to check if the query was excuted or not ..
so something like this might help:
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

02-21-04, 01:56 PM
|
 |
Aspiring Coder
|
|
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
|
|
Thnx Nevermind..that did the trick.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|