I have no idea why it's doing it. I know I'm missing something, but everything looks right to me. When you submit the registration form it just does the error, and properties say its the process page, so this code below. Sorry posting it all, I'm just not sure period.
<?php
require('connect.php');
//check all the posted info
function getInfo() {
$error = array();
$fname = validateFirstname($_POST['fname']);
$lname = validateLastname($_POST['lname']);
$uname = validateUsername($_POST['uname']);
$email = validateEmail($_POST['email']);
$password = validatePass($_POST['password1'], $_POST['password2']);
$phone = validatePhone($_POST['phone']);
//check for errors
error();
}
function validateFirstname($str) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[a-zA-Z0-9]{2,}$/',$str)) {
return preg_match('/^[a-zA-Z0-9]{2,}$/',$str);
} else {
$error[] = 'Please enter a valid first name!';
}
}
function validateLastname($str) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[a-zA-Z0-9]{2,}$/',$str)) {
return mysql_real_escape_string($str);
} else {
$error[] = 'Please enter a valid last name!';
}
}
function validateUsername($str) {
//connect to database
$link = mysql_connect($db_host, $db_user, $db_pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name);
//pull usernames to make sure new is unique
$sql = "SELECT username FROM users WHERE username = '".$str."'";
if ($sql == "") {
//This allows just alphanumeric characters and must be 4 - 15 characters.
if (preg_match('/^[a-zA-Z0-9]{4,15}$/',$str)) {
return mysql_real_escape_string($str);
} else {
$error[] = 'Please enter a valid user name!';
}
} else {
$error[] = 'This user name is already registered!';
}
}
function validateEmail($str) {
//connect to database
$link = mysql_connect($db_host, $db_user, $db_pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name);
//pull usernames to make sure new is unique
$sql = "SELECT email FROM users WHERE email = '".$str."'";
if ($sql == "") {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$str)) {
return mysql_real_escape_string($str);
}else{
$error[] = 'Please enter a valid email!';
}
} else {
$error[] = 'This email is already registered!';
}
}
function validatePass($str, $str2) {
//This allows just alphanumeric characters and must be 6-15 characters.
if ($str == $str2) {
if (preg_match('/^[a-zA-Z0-9]{6,15}$/',$str)) {
return md5(mysql_real_escape_string($str));
} else {
$error[] = 'Please enter a valid password!';
}
} else {
$error[] = 'Passwords do not match!';
}
}
function validatePhone($str) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[0-9]{0,11}$/',$str)) {
return mysql_real_escape_string($str);
} else {
$error[] = 'Please enter a valid phone number!';
}
}
function error() {
if ($error[] == '') {
addInfo();
} else {
echo "<a href='javascript: history.go(-1)'><-- Go Back</a><br>";
echo $error[];
}
}
function addInfo() {
//setcookie("site_user", $Name, time() + 31536000, "/");
//setcookie("site_pass", $Password, time() + 31536000, "/");
//Connect to database from here
$link = mysql_connect($db_host, $db_user, $db_pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//activation link
$a = md5(uniqid(rand(), true));
//select the database | Change the name of database from here
mysql_select_db($db_name);
$sql="INSERT INTO users (firstname,lastname,email,username,password,phone,active,ip,rank,acctcreated) VALUES ('$fname','$lname','$uname',$email','$lastpass','$phone',$a','$ip','$rank',NOW())";
}
// Send the email:
$message = " To activate your account, please click on this link:\n\n";
$message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
mail($Email, 'Registration Confirmation', $message, 'From:'.EMAIL);
// Flush the buffered output.
// Finish the page:
echo '<div class="success">Thank you for registering! A confirmation email has been sent to ' . $Email .' Please click on the Activation Link to Activate your account </div>';
?>