Jump to content

username check


jakebur01

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/92338-username-check/#findComment-473099
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/92338-username-check/#findComment-473113
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.