All fields are required! Password must be 4+ characters. Username and email must be unique.
prepare($query); $stmt->execute(array( ':username' => $_POST['username'], ':email' => $email )); $existing = $stmt->fetchObject(); if ($existing) { if ($existing->username == $_POST['username']) { $errors['username'] = "That username is already in use."; } if ($existing->email == $email) { $errors['email'] = "That email address is already in use."; } } } if (!empty($_POST['newuser']) && empty($errors)) { $hasher = new PasswordHash(8, FALSE); $password = $hasher->HashPassword($_POST['password']); $query = "INSERT INTO users (firstname, lastname, username, password, email, created, usertype) VALUES (:firstname, :lastname, :username, :password, :email, NOW(), :usertype)"; $stmt = $yaptc_db->prepare($query); $success = $stmt->execute(array( ':firstname' => $_POST['firstname'], ':lastname' => $_POST['lastname'], ':username' => $_POST['username'], ':password' => $password, ':email' => $_POST['email'], ':usertype' => $_POST['usertype'], )); if ($success) { $message = "Account created."; } else { echo "Account could not be created. Please try again later."; } } ?>