PREVENTING DUPLICATE USERNAME
Posted: Wed Jan 29, 2003 8:46 am
I am trying to prevent users from choosing a username that is already in the MYSQL database when they register with the site. This is the code i am trying to use (you can see i am new to this!). It is not giving me any errors but at the same it is not checking that the username already exists. Thanks for the help.
<html>
<body>
<?php
mysql_connect ("localhost", "supaper", "supaper5") or die("Could not Connext");
mysql_select_db("supaper");
?>
<?
$result=mysql_query("Select * from TUTORS where tutor_username = '$tut_uname'");
if(mysql_num_rows($result)>0){
echo ("Username has already been taken!");
}
else
mysql_query("INSERT INTO TUTORS(tutor_username, tutor_pwd, tutor_name, tutor_email, tutor_address, tutor_phone, tutor_course, tutor_startdate)
VALUES ('$tut_uname', '$tut_pwd', '$tut_name', '$tut_email', '$tut_addr', '$tut_phone', '$tut_phone', SYSDATE() )");
$redirect = "../main/Tutor_RegisterSuccess_Page.php";
echo "<script language='Javascript'>\n
document.location.replace('$redirect');
</script>\n";
die();
?>
</body>
</html>
<html>
<body>
<?php
mysql_connect ("localhost", "supaper", "supaper5") or die("Could not Connext");
mysql_select_db("supaper");
?>
<?
$result=mysql_query("Select * from TUTORS where tutor_username = '$tut_uname'");
if(mysql_num_rows($result)>0){
echo ("Username has already been taken!");
}
else
mysql_query("INSERT INTO TUTORS(tutor_username, tutor_pwd, tutor_name, tutor_email, tutor_address, tutor_phone, tutor_course, tutor_startdate)
VALUES ('$tut_uname', '$tut_pwd', '$tut_name', '$tut_email', '$tut_addr', '$tut_phone', '$tut_phone', SYSDATE() )");
$redirect = "../main/Tutor_RegisterSuccess_Page.php";
echo "<script language='Javascript'>\n
document.location.replace('$redirect');
</script>\n";
die();
?>
</body>
</html>