Oh, okay. So, lets setup for debugging. At the top of the script put this line
error_reporting(E_ALL);
And change
$result = mysql_db_query($database, $query, $connection);
//to
$result = mysql_db_query($database, $query, $connection) or die(mysql_error());
And change the header redirect statements to
echo $query."<br><br>Rows: ".mysql_num_rows($result);
If there's an error, that should help you find it. For the SQL queries that are echoed, run them against the database also to make sure that they are right...