My form worked, but when i put lastname(lname) field won't work
<?php
include "connect.php";
echo "<h1>Register</h1>";
?>
<div style="color:#F00">
<?php
date_default_timezone_set('Europe/Zagreb');
date_default_timezone_get();
ini_get('timezone.default');
getenv('TZ');
$num = 0;
$submit = $_POST['submit'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
date_default_timezone_get();
$date = date("Y-m-d G:i:s");
if ($submit){
if (!$username){
$num ++;
echo "<tr><td>".$num.". Username required.</td></tr><br />";
}
if (!$fname){
$num ++;
echo "<tr><td>".$num.". Firstname required.</td></tr><br />";
}
if (!$lname){
$num ++;
echo "<tr><td>".$num.". Lastname required.</td></tr><br />";
}
if (!$password){
$num ++;
echo "<tr><td>".$num.". Password required.</td></tr><br />";
}
if (!$email){
$num ++;
echo "<tr><td>".$num.". Email required.</td></tr><br />";
}
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 ($fname){
if (strlen($fname) > 20){
$num ++;
echo "<tr><td>".$num.". Firstname is too long.(3-20)</td></tr><br />";
}
}
if ($fname){
if (strlen($fname) < 3){
$num ++;
echo "<tr><td>".$num.". Firstname is too short.(4-20)</td></tr><br />";
}
}
if ($lname){
if (strlen($lname) > 20){
$num ++;
echo "<tr><td>".$num.". Lastname is too long.(3-20)</td></tr><br />";
}
}
if ($lname){
if (strlen($lname) < 3){
$num ++;
echo "<tr><td>".$num.". Lastname 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 ($username){
$sql = mysql_query("SELECT * FROM users WHERE username='$username'")or die(mysql_error());
if(mysql_num_rows($sql) > 0){
$num ++;
echo "<tr><td>".$num.". The username '<b>".$username."</b>' already exists.</td></tr><br />";
}
}
$name = $_FILES["img"]["name"];
$tmp = $_FILES["img"]["tmp_name"];
$error = $_FILES["img"]["error"];
if ($error > 0){
$num ++;
echo "<tr><td>".$num.". ERROR uploading file!</td></tr><br />";
}
if (!$name){
$num ++;
echo "<tr><td>".$num.". Profile image required.</td></tr><br />";
}
if ($num == 0){
echo "Success!";
include "connect.php";
$location = "img/$name";
move_uploaded_file($tmp,"img/".$name);
$queryreg = mysql_query("
INSERT INTO users VALUES ('','$fname','$lname','$username','$password','$email','$location','$date')
");
echo "You have been registered.<a href='index.php'>Click here to return to login page.</a>";
}
}
?>
</div>
<form action="register.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
Firstname:
</td>
<td>
<input type="text" name="fname" value="<?php echo $fname; ?>" />
</td>
</tr>
<tr>
<td>
Lastname:
</td>
<td>
<input type="text" name="lname" value="<?php echo $lname; ?>" />
</td>
</tr>
<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>
Email:
</td>
<td>
<input type="text" name="email" value="<?php echo $email; ?>" />
</td>
</tr>
<tr>
<td>
Profile image:
</td>
<td>
<input type="file" name="img" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Register" />
</td>
</tr>
</form>