Problem with PHP and SQL query

I have a form in which the user can view and edit data from a database. When they click on the submit button an UPDATE query is executed, but this query differs from user to user, based on a number:


if ($number == 1) {
    $sql = "UPDATE table SET ... ";
} else if ($number == 2) {
    $sql = "UPDATE table SET ... ";
} else {
    $sql = "UPDATE table SET ... ";
}

$result = mysqli_query($conn,$sql); // $conn is created earlier in the code

header('Location: home.php');

The strange thing is that when $number is equal to 1 everything works, the query is executed and the user is successfully redirected to the homepage. When $number has another value, the query works but the redirect doesn’t: I get a “File not found” Firefox message and I have to manually type “home.php” in the URL bar to continue working.

Do you have any idea why this is happening?

The only thing I could think of is you are getting some kind of error which is causing output, which is causing your header to fail. Check your PHP error logs and see if anything suspicious is showing up.

Also, double-check that what you sent us is properly representative of what you actually have. What you have there -shouldn’t- cause any issues as far as I can see.

The problem was that I happened to use some $_POST values without checking whether they were set or not :slight_smile: