Sign up code - 1 field not working

I have this code and some problems… It checks if last name is empty that works but i can’t take the value from it. I mean registration works but i submit no value to last name (when i add that check to see if last name is at least 3 characters i can’t submit at all)

This is my java code for submit

[code]function signup(){
var fn = _(“firstname”).value;
var ln = _(“lastname”).value;
var u = _(“username”).value;
var e = _(“email”).value;
var p1 = _(“pass1”).value;
var p2 = _(“pass2”).value;
var c = _(“country”).value;
var g = _(“gender”).value;

var status = _("status");
if(u == "" || e == "" || p1 == "" || p2 == "" || c == "" || g == "" || fn == "" || ln == ""){
	status.innerHTML = "<strong style=\"font-size:13px; color:#F00;\">Please complete all fields before submitting</strong>";
} else if(p1 != p2){
	status.innerHTML = "<strong style=\"font-size:13px; color:#F00;\">Your passwords do not match!</strong>";
}  else {

	status.innerHTML = '';
	var ajax = ajaxObj("POST", "index.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
            if(ajax.responseText != "signup_success"){
				status.innerHTML = ajax.responseText;
				_("signupbtn").style.display = "block";
			} else {
				window.scrollTo(0,0);
				_("indlayout").innerHTML = "Succes etc........";
			}
        }
    }
    ajax.send("fn="+fn+"&ln="+ln+"&u="+u+"&e="+e+"&p="+p1+"&c="+c+"&g="+g);
}

}[/code]

And this is my PHP Code:

[php]<?php
// Ajax calls this REGISTRATION code to execute
if(isset($_POST[“fn”])){
// CONNECT TO THE DATABASE
include_once(“php_include/db_conx.php”);
// GATHER THE POSTED DATA INTO LOCAL VARIABLES
$fn = preg_replace(’#[^a-z]#i’, ‘’, $_POST[‘fn’]);
$ln = preg_replace(’#[^a-z]#i’, ‘’, $_POST[‘ln’]);
$u = preg_replace(’#[^a-z0-9]#i’, ‘’, $_POST[‘u’]);
$e = mysqli_real_escape_string($db_conx, $_POST[‘e’]);
$p = $_POST[‘p’];
$g = preg_replace(’#[^a-z]#’, ‘’, $_POST[‘g’]);
$c = preg_replace(’#[^a-z ]#i’, ‘’, $_POST[‘c’]);
$es = $_POST[‘e’];
$regex = ‘/^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$/’;
// GET USER IP ADDRESS
$ip = preg_replace(’#[^0-9.]#’, ‘’, getenv(‘REMOTE_ADDR’));
// DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL
$sql = “SELECT id FROM users WHERE username=’$u’ LIMIT 1”;
$query = mysqli_query($db_conx, $sql);
$u_check = mysqli_num_rows($query);
// -------------------------------------------
$sql = “SELECT id FROM users WHERE email=’$e’ LIMIT 1”;
$query = mysqli_query($db_conx, $sql);
$e_check = mysqli_num_rows($query);
// FORM DATA ERROR HANDLING
if($fn == “” || $ln = “” || $u == “” || $e == “” || $p == “” || $g == “” || $c == “”){
echo “<strong style=“font-size:12px; color:#F00;”>Fill out all of the form data”;
exit();
}
else if (strlen($fn) < 3){
echo “<strong style=“font-size:12px; color:#F00;”>First name must be at least 3 characters”;
exit();
}
else if (strlen($ln) < 3){
echo “<strong style=“font-size:12px; color:#F00;”>Last name must be at least 3 characters”;
exit();
}
else if (strlen($u) < 4 || strlen($u) > 16) {
echo “<strong style=“font-size:12px; color:#F00;”>Username must be at least 4 characters”;
exit();
}
else if (is_numeric($u[0])) {
echo ‘Username cannot begin with a number’;
exit();
}
else if ($u_check > 0){
echo “<strong style=“font-size:12px; color:#F00;”>The username you entered is alreay taken</strong”;
exit();
}
else if (!preg_match($regex, $es)) {
echo “<strong style=“font-size:12px; color:#F00;”>Email address is not valid</strong”;
exit();
}
else if ($e_check > 0){
echo “<strong style=“font-size:12px; color:#F00;”>That email address is already in use in the system”;
exit();
} else if(strlen($p) < 6)
{
echo “<strong style=“font-size:12px; color:#F00;”>Password must be at least 6 characters long”;
}

 else {
   // END FORM DATA ERROR HANDLING
    // Begin Insertion of data into the database
	// Hash the password and apply your own mysterious unique salt
	$p_hash = md5($p);
	// Add user info into the database table for the main site table
	$sql = "INSERT INTO users (firstname, lastname, username, email, password, gender, country, ip, signup, lastlogin, notescheck)       
	        VALUES('$fn','$la','$u','$e','$p_hash','$g','$c','$ip',now(),now(),now())";
	$query = mysqli_query($db_conx, $sql); 
	$uid = mysqli_insert_id($db_conx);
	// Establish their row in the useroptions table
	$sql = "INSERT INTO useroptions (id, username, background) VALUES ('$uid','$u','original')";
	$query = mysqli_query($db_conx, $sql);
	// Create directory(folder) to hold each user's files(pics, MP3s, etc.)
	if (!file_exists("user/$u")) {
		mkdir("user/$u", 0755);
	}
	// Email the user their activation link
	$to = "$e";							 
	$from = "[email protected]";
	$subject = 'Confirm your Social Bites account';
	$message = 'message...';
	$headers = "From: $from\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
	mail($to, $subject, $message, $headers);
	echo "signup_success";
	exit();
}
exit();

}[/php]

I really can’t find what’s wrong with this. Thanks.

Nevermid, i missed one = in my code so i asigned a null value to last name instead of checking for empty field

Sponsor our Newsletter | Privacy Policy | Terms of Service