registration page
Posted: Tue Apr 01, 2008 10:36 am
Hey. i have another problem now....ive created a user register form now aswell. i can add to the database fine but when it checks if a user is already taken, it constantly shows this:
Sorry, there the username Dave is already taken.
Try again
this is when ive entered the name daniel cos this is in my database. so it should say daniel not dave.
I can add a totally new user that does not have a username already stored in the database fine thats not a prob.
Could you help please????
register.php
<?php
$host = "localhost"; //login to the server
$username = "Dave"; //username login
$password = "ozxoka"; //password login
$db_name = "logintest"; //login test and register
$tbl_name = "members"; //members tabel
// connect to the mysql server
$link = mysql_connect($host, $username, $password)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($db_name)
or die ("Could not select database because ".mysql_error());
// check if the username is taken
$check = "select id from $tbl_name where username = '".$_POST['username']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $username is already taken.<br>";
echo "<a href=userregistration.php>Try again</a>";
exit;
}
else {
// insert the data
$insert = mysql_query("insert into $tbl_name values ('NULL', '".$_POST['username']."', '".$_POST['password']."')")
or die("Could not insert data because ".mysql_error());
// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=login.php>log in</a>";
}
?>
userregistration.php
<html><head>
<title>User Registration</title>
</head><body>
<form action="register.php" method="post">
Enter a Username: <input type="text" name="username" size="20"><br>
Enter a Password: <input type="password" name="password" size="20"><br>
<input type="submit" value="Sign Up">
</form>
</body></html>
Sorry, there the username Dave is already taken.
Try again
this is when ive entered the name daniel cos this is in my database. so it should say daniel not dave.
I can add a totally new user that does not have a username already stored in the database fine thats not a prob.
Could you help please????
register.php
<?php
$host = "localhost"; //login to the server
$username = "Dave"; //username login
$password = "ozxoka"; //password login
$db_name = "logintest"; //login test and register
$tbl_name = "members"; //members tabel
// connect to the mysql server
$link = mysql_connect($host, $username, $password)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($db_name)
or die ("Could not select database because ".mysql_error());
// check if the username is taken
$check = "select id from $tbl_name where username = '".$_POST['username']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $username is already taken.<br>";
echo "<a href=userregistration.php>Try again</a>";
exit;
}
else {
// insert the data
$insert = mysql_query("insert into $tbl_name values ('NULL', '".$_POST['username']."', '".$_POST['password']."')")
or die("Could not insert data because ".mysql_error());
// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=login.php>log in</a>";
}
?>
userregistration.php
<html><head>
<title>User Registration</title>
</head><body>
<form action="register.php" method="post">
Enter a Username: <input type="text" name="username" size="20"><br>
Enter a Password: <input type="password" name="password" size="20"><br>
<input type="submit" value="Sign Up">
</form>
</body></html>