1
I’m trying to get my log page to show all forgotten fields messages together as in this example:
But it only shows in parts:
1 - "Username already exists" and "Email already exists" or
2 - "Please Insert a username", "Please Insert a password" and "Please Insert a email" or
3 - "Username must have Less than 16 characters" and "Password must have 8 or more characters"
Is there any solution to this?
<?php
$page = "Register";
include "header.php";
if(isset($_POST["register"])){
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
if(!empty($username) && !empty($password) && !empty($email)){
if(strlen($username) < 17 && strlen($password) > 7){
$checkusername = mysql_query("SELECT `id` FROM `database`.`user` WHERE `username` = '".$username."'");
$checkemail = mysql_query("SELECT `id` FROM `database`.`user` WHERE `email` = '".$email."'");
if(mysql_num_rows($checkusername) == 0 && mysql_num_rows($checkemail) == 0){
$insert = mysql_query("INSERT INTO `database`.`user`(`username`,`password`,`email`) VALUES ('".$username."','".$password."','".$email."')") or die(mysql_error());
?><p><?php echo "You are Registered"; ?></p><?php
}
else{
if(mysql_num_rows($checkusername) > 0){
$error[] = "Username already exists";
}
if(mysql_num_rows($checkemail) > 0){
$error[] = "Email already exists";
}
foreach($error as $value){
?><p><?php echo "'".$value."'<br>"; ?></p><?php
}
}
}
else{
if(strlen($username) > 16){
$error[] = "Username must have less than 16 characters";
}
if(strlen($password) < 8){
$error[] = "Password must have 8 or more characters";
}
foreach($error as $value){
?><p><?php echo "'".$value."'<br>"; ?></p><?php
}
}
}
else{
if(empty($username)){
$error[] = "Please insert a username";
}
if(empty($password)){
$error[] = "Please insert a password";
}
if(empty($email)){
$error[] = "Please insert a email";
}
foreach ($error as $value) {
?><p><?php echo "'".$value."'<br>"; ?></p><?php
}
}
}
?>
<div id="loginform">
<form name="loginform" method="post">
<table cellpadding="0" id="tb">
<tr>
<td colspan="2"><div class="loginheader"><h2>Register</h2></div></td>
</tr>
</table>
<table cellpadding="0" id="REGOPTIONS">
<tr>
<td class="field">Username:</td>
<td><input type="text" class="text" name="username"></td>
</tr>
<tr>
<td class="field">Password:</td>
<td><input type="password" class="text" name="password"></td>
</tr>
<tr>
<td class="field">Email:</td>
<td><input type="email" class="text" name="email"></td>
</tr>
</table>
<table cellpadding="0">
<tr>
<td class="field"></td>
<td><input type="submit" class="submitbutton" name="register" value="Register" /></td>
</tr>
</table>
</form>
</div>
<?php
include "footer.php";
?>
very good @Bacco
– Otto
@Lukaz11: See in this answer how to use the
mysqli
to avoid SQL Injection, and quote problems in the fields: http://answall.com/a/14757/70– Bacco