Here is my code:
<?php require("functions.php"); $_SESSION['errors'] = NULL; if(isset($_POST['submit'])){ $username = $_POST['username']; $password1 = $_POST['password']; $password2 = $_POST['password2']; $fname = $_POST['firstn']; $lname = $_POST['lastn']; $gender = $_POST['gender']; $errors[] = array(); if(empty(trim($username))){ $errors[] = "Please enter a username"; } if(empty(trim($password1))){ $errors[] = "Please enter a password"; } if(empty(trim($password2))){ $errors[] = "Please confirm your password"; } if(empty(trim($fname))){ $errors[] = "Please enter your first name"; } if(empty(trim($lname))){ $errors[] = "Please enter your last name"; } if($gender == "default"){ $errors[] = "Please select your gender"; } if($password1 != $password2){ $errors[] = "Your passwords do not match"; } $query = mysql_query("SELECT COUNT(`user_id`) as `id_exists` FROM `users` WHERE `username` = '".$username."'"); if(mysql_num_rows($query) != 0){ $errors[] = "Username already exists"; } if(isset($username[5])){ $errors[] = "Your username needs to be 6 characters or more"; } if(isset($username[31])){ $errors[] = "Your username is too long"; } if(isset($fname[31])){ $errors[] = "Your first name is too long"; } if(isset($lname[31])){ $errors[] = "Your last name is too long"; } if(empty($errors[])){ $username = mysql_real_escape_string(strtolower($username)); $password2 = md5(add_salt($password2)); $fname = mysql_real_escape_string(strtolower($fname)); $lname = mysql_real_escape_string(strtolower($lname)); if(($gender == "male") || ($gender == "female")){ $gender = $gender; // set male to m, female to f } else { header("Location: index.php"); } $query1 = mysql_query("INSERT INTO users (`user_id`,`fname`,`lname`,`gender`,`passwd`,`profile_pic`,`username`) VALUES ('','".$fname."','".$lname."','".$gender."','".$password2."','','".$username."')") or ($fail = true); if($fail === true){ $errors[] = "The insert failed. Please try again later."; $_SESSION['errors'] = $errors[]; header("Location: index.php?error=true"); } else { header("Location: index.php?success=true"); } } else { $_SESSION['errors'] = $errors[]; header("Location: index.php?error=true"); } } else { header("Location: index.php"); } ?>Function.php:
<?php session_start(); error_reporting(1); mysql_connect("localhost","root","root") or die(mysql_error()); mysql_select_db("general"); function add_salt($string){ $string .= "A4dceed"; return $string; } function is_logged_in(){ if((isset($_SESSION['username'])) || (isset($_SESSION['uid']))){ // return true; } else { // return false; } } ?>