This is a discussion on "simple check if user exists" within the PHP Forum section. This forum, and the thread "simple check if user exists are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
simple check if user exists
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
simple check if user exists
hi- first post, so i hope this is worthy-
i have a script that checks a mysql db to see if a- the user exists b- the password is the same as what was sent from the form the script below works fine for point b, but what about a? if the user never "registered" (and therefore, is not in the db) how can i check for that? YOu can see in my code where i commented the part that is not working
|
|
|
|
|||
|
Re: simple check if user exists
I know you're probably just learning, but using $_GET is not secure, you should use $_POST and your password is not encrypted, but you can look into that later. Just a warning! Maybe you should make your query like the one below, this way it will only pull out the user if the username and the password are correct: $sql="SELECT * FROM users WHERE userName='$un' AND password='$ps'"; If you need any more help, give us a yell. Last edited by jimz; Aug 22nd, 2007 at 10:14. Reason: bad grammar :( |
|
|||
|
Re: simple check if user exists
Hi Mlecho
I think the problem is that when there is no matching user name the while loop never executes so you never see your 'user does not exist' message. Specifically: mysql_fetch_assoc will return false on an empty result set. Jimz's solution won't work i don't think for the same reason. You want to check if the query returned anything. You could try a test:
Assuming you are enforcing unique user names why are you using a loop at all? Or use Jimz's SQL solution and do it all in one SQL line but watch out for SQL Injection In the equivalent Perl DBI module you can test for undefined to see if the result set was empty. I think the above is ok but I'm really not sure what the best way to test for an empty result set should be in PHP. Justin Last edited by Kropotkin; Aug 22nd, 2007 at 15:37. Reason: typo |
![]() |
| Tags |
| mysql |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Check to see if a cfwindow exists | BenR41 | Other Programming Languages | 0 | Feb 25th, 2008 12:22 |
| fastest way to check if table exists | CloudedVision | PHP Forum | 3 | Feb 20th, 2008 16:15 |
| Check if user has clicked an adwords ad. | Kimochi | JavaScript Forum | 4 | Mar 4th, 2007 16:31 |
| Check whether URL exists | Sheepymot | PHP Forum | 2 | Jul 24th, 2005 08:16 |
| Check User | Amari | Classic ASP | 10 | Dec 20th, 2004 02:29 |