hi all ive tried different things to solve this like remove any white space in php but i cant seem to get rid of this error can anyone suggest anything please.
<?php
include("connect.php");
?> <?php
// define variables and set to empty values
$usernameErr = $emailErr = $passwordErr = $sexErr = $dayErr = $monthErr = $yearErr = "";
$username = $email = $password = $sex = $day = $month = $year = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["username"])) {
$usernameErr = "Username is required";
} else {
$username = $_POST["username"];
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$username)) {
$usernameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = $_POST["email"];
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["password"])) {
$passwordErr = "Password is required";
} else {
$password = $_POST["password"];
// check if password only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$password)) {
$passwordErr = "Only letters and white space allowed";
}
}
if (empty($_POST["sex"])) {
$sexErr = "Member type is required";
} else {
$sex = $_POST["sex"];
}
if (empty($_POST["day"])) {
$dayErr = "Day of birth is required";
} else {
$day = $_POST["day"];
}
if (empty($_POST["month"])) {
$monthErr = "Month of birth is required";
} else {
$month = $_POST["month"];
}
if (empty($_POST["year"])) {
$yearErr = "Year of birth is required";
} else {
$year = $_POST["year"];
}
$sql = "INSERT INTO users (username, email, password, sex, day, month, year)
VALUES ('$username', '$email', '$password', '$sex', '$day', '$month', '$year')";
if ($conn->query($sql) === TRUE) {
header("location: profile.php");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
ive tried adding
flush_ob();
above it has read in forums and also the following
if (headers_sent()) {
die("Redirect failed. Please click on this link: <a href=...>");
}
but nothing seems to be working can anyone suggest anything please :)