$sql = "INSERT INTO users (name, email) VALUES ('$name', '$email')"; if ($conn->query($sql) === TRUE) { // Successful insert, redirect to another page header('Location: http://www.example.com/success-page.php'); exit(); // Ensure no further code is executed after the redirect } else { echo "Error: " . $sql . " " . $conn->error; }