How i put to my register error if user already exists.
My code:
<?php
include "connect.php";
echo "<h1>Register</h1>";
$num = 0;
$submit = $_POST['submit'];
$username = $_POST['username'];
$password = $_POST['password'];
if ($submit){
if ($username){
if (strlen($username) > 20){
$num ++;
echo "<tr><td>".$num.". Username is too long.(3-20)</td></tr><br />";
}
}
if ($username){
if (strlen($username) < 3){
$num ++;
echo "<tr><td>".$num.". Username is too short.(4-20)</td></tr><br />";
}
}
if ($password){
if (strlen($password) > 20){
$num ++;
echo "<tr><td>".$num.". Password is too long.(6-20)</td></tr>";
}
}
if ($password){
if (strlen($password) < 5){
$num ++;
echo "<tr><td>".$num.". Password is too short.(6-20)</td></tr>";
}
}
if ($num == 0){
echo "Success!";
include "connect.php";
$queryreg = mysql_query("
INSERT INTO users VALUES ('','$username','$password')
");
echo "You have been registered.<a href='index.php'>Click here to return to login page.</a>";
}
}
?>
<form action="register.php" method="post">
<table>
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="username" value="<?php echo $username; ?>" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Register" />
</td>
</tr>
</form>