Forum Moderators: coopster
"This username is already in use. Please try another."
You obviously must already be as far as getting a list of users and checking against it, otherwise your login wouldn't work, so let's skip that part. In terms of sending them back to the registration page, you can use
header("Location: reg_page.php");
exit();
As for the error message, you can handle that many ways but very easy would be to send them back using
header("Location: reg_page.php?error=name_taken");
exit();
Then in reg_page.php
if (isset($_GET['error']) && $_GET['error'] == 'name_taken') {
$msg = "This username is already in use. Please try another.";
}
Tom
ill try again :p
i need a script or something that will stop duplicate users and/or emails being entered into my MySQL database.
this is the script im using to enter the data into the database:
file=signup.html
<form action="make.php" method="post">
Username Desired: <input type="text" name="username" size="10">
Password Desired: <input type="password" name="password" size="10">
E-mail: <input type="text" name="email" size="10">
<input type="submit" value="submit" name="submit">
</form>
which takes u to here:
<?
$conn = mysql_connect("localhost","USERNAME","PASSWORD");
$db = mysql_select_db("users");
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$result= MYSQL_QUERY("INSERT INTO users (id, username, password, email)".
"VALUES ('NULL', '$username', '$password', '$email')");
echo "Your name and password have been submitted into our database.";
?>
which puts the data into the database which in turn allows u to login via the login page. i need something in the 2nd script that will allow me to stop ppl entering duplicate usernames or email.
PS. this isnt meant to look good or anything atm, im just testing / tweaking things for my skool project.
thanx for ur help.
$query = SELECT FROM users WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());if (mysql_num_rows($result)>0)
{
$error_string[] = "Username already exists, please try again!<br>";
}$query2 = SELECT FROM users WHERE password = '$password'";
$result2 = mysql_query($query2) or die(mysql_error());if (mysql_num_rows($result2)>0)
{
$error_string[] = "Password already exists, please try again!";
}if (!empty($error_string))
{
foreach ($error_string as $message)
{
echo $message;
}
exit;
}
:)