Jump to content

Checking duplicate user in a DATABASE?


bilis_money

Recommended Posts

Hello bilis
Anyways, I ran into this problem myself, but now I can provide you with the answer  :D
[code]
$query  = "SELECT username FROM users WHERE username='$username'";
$result = mysql_query($query);
$checkUsername = mysql_fetch_array($result);

if!isset($checkUsername['username']){ //if the username is not taken
//do something
} else {
//report error
}
[/code]
Hope this helps
I normally set this into the database that the username has to be an unique value
Also silentwf I do not recomment using:

[code]
<?php
if !isset($checkUsername[...
// Instead use
if (!in_array($username, $checkUsername)) { ...
?>
[/code]
xec now your obsetly making it difficult, you need the where clausule otherwise you can not check where something is equal/duplicate

[code]
$query = "SELECT `username`, COUNT(`username`) AS `DuplicateEntries` FROM `users` WHERE `username`='$username'";// will possibly not work... therefore rather use:
$Query = mysql_query("SELECT `username` FROM `users` WHERE `username`='$username'");
$Rows = count(mysql_fetch_array($Query));
[/code]

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.