jakebur01 Posted February 21, 2008 Share Posted February 21, 2008 I am needing to check to see if a username is already in use or not. I want to query my mysql database customer table to see. Fields id, user, pass, email. What would the query and loop look like? Quote Link to comment https://forums.phpfreaks.com/topic/92338-username-check/ Share on other sites More sharing options...
Ken2k7 Posted February 21, 2008 Share Posted February 21, 2008 Hello, <?php // your database connection $username = "Ken"; // username you want to check $sql = mysql_query("SELECT username FROM customer WHERE username='$username'"); $num = mysql_num_rows($sql); if ($num > 0) { // do something => username exists } else { // do something else => username doesn't exist } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/92338-username-check/#findComment-473099 Share on other sites More sharing options...
jakebur01 Posted February 21, 2008 Author Share Posted February 21, 2008 if i put my connection on the page, is their a possibility that ppl can see it? if so, how? why do most ppl use include files? Quote Link to comment https://forums.phpfreaks.com/topic/92338-username-check/#findComment-473103 Share on other sites More sharing options...
Ken2k7 Posted February 21, 2008 Share Posted February 21, 2008 if i put my connection on the page, is their a possibility that ppl can see it? if so, how? why do most ppl use include files? Hello, Well it depends. If you show them the PHP file, then yes. You can't page source the connection data if that's what you mean. And people use include files for flexibility. Say you have a few PHP files that require database connections. Rather than writing it on every page, you just include the file. Also, it makes it easier for you to edit one file than multiple file if you either mistyped your username/password or whatever. Or maybe you changed your password. Then you would have to edit all the files, but with include, you just edit one file. Ken Quote Link to comment https://forums.phpfreaks.com/topic/92338-username-check/#findComment-473113 Share on other sites More sharing options...
jakebur01 Posted February 21, 2008 Author Share Posted February 21, 2008 thank you , ken Quote Link to comment https://forums.phpfreaks.com/topic/92338-username-check/#findComment-473116 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.