Help on User Registration using PHP

admin

Administrator
Staff member
Hey! there,
I am currently working on a database project which needs user registration. The problem is that the username must be unique and I thought of this code and wrote it!

<?php if ( isset($uname) ): ?>
<?php
$result = mysql_query( "SELECT * FROM alumni");
while ( $row = mysql_fetch_array($result) )

{if ($uname == $row[uname]) {$uv = '';} else {$uv = 1;}}
?>

But, the problem with this snippet is that, when I exucute, it only checks if it is the same as the last added username and exits. So, I land up having more than one similar username's.


I also tried the next code, but i ended up having the same trouble.

$sql = "SELECT id from users where uname=$uname";
$result = mysql_query($sql);

if(mysql_num_rows($result)) {
# the username is taken
}
else {
# the username is not taken
}

If anyone is willing to help, I'd be glad.
 
Back
Top