as you can see I'm trying to create a registration page and I have completely mucked up all my if statements and else statements, I'm completely lost and am just chucking in random brackets I'm that lost I was wondering if anybody could point me in the direction of sorting this out.
<?php
require_once './include/config.php';
require_once './include/functions/cleanString.php';
if ($_POST ['submit']) {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$trn_date = date("Y-m-d H:i:s");
$error_check = array();
if (!empty($username)) {
$username = cleanString($username);
$query ="SELECT * FROM users WHERE Username='$username'";
$result = mysqli_query($con, $query) or exit ("Error in query: $query. ");
if(mysqli_num_rows($result) > 0) { //check if there is already an entry for that username
$error_check['username'] = 'Username already in use';
}
if(ctype_alpha($username)) {
}else {
$error_check ['username'] = 'Name must be alphabetic characters only';
}
} else {
$error_check ['username'] = 'Please enter a username';
}
if (!empty($email)) {
$email = cleanString($email);
$query ="SELECT * FROM users WHERE email='$email'";
$result = mysqli_query($con, $query) or exit ("Error in query: $query. ");
if(mysqli_num_rows($result) > 0) { //check if there is already an entry for that username
$error_check['email'] = 'EmaIl already in use';
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_check ['email'] = 'Please enter a valid email adress';
}
} else {
$error_check ['email'] = 'Please enter a email adress';
}
if (!empty($password)) {
$password = cleanString($password);
if (preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["password"]) === 0) {
$error_check ['password'] = "The password must contain lower case characters, upper case characters and numbers. It's length should be between 8 and 32 characters.";
}
}
} else {
$error_check ['passsword'] = 'Please enter a password';
}
if (empty($error_check)) {
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['message'] = 'Registration Sucessful';
header("Location: ./reg2.php");
} else {
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['errors'] = $error_check;
$query = mysqli_query($con, "INSERT into `users` (username, password, email, registerdate) VALUES ('$username', '".md5($password)."', '$email', '$trn_date')");
$_SESSION['message'] = 'There were errors in your registration, please correct the errors and try again!';
header("Location: ./reg2.php");
}
}
?>
Aucun commentaire:
Enregistrer un commentaire