Reputation: 73
I'm trying to redirect this PHP page to another page as soon as I get successful update in the database .. but I get a warning from PHP and nothing happens .. Below is the code .. Where did I go wrong ?
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="css/madscore.css">
</head>
<body>
<?php
require('../database/connect.php');
?>
<?php
$id = $_POST["id"];
$value = $_POST["score"];
database_connect();
$query = "update people set Score= Score +".$value." WHERE ID ='".$id."'";
$result = $connection->query($query);
if($result)
{
?>
<?php
@header("Location: http://www.europe-zone.com/");
exit();
}
?>
</body>
</html>
Upvotes: 0
Views: 121
Reputation: 6645
<?php
require('../database/connect.php');
$id = $_POST["id"];
$value = $_POST["score"];
database_connect();
$query = "update people set Score= Score +".$value." WHERE ID ='".$id."'";
$result = $connection->query($query);
if($result)
{
?>
<?php
@header("Location: http://www.europe-zone.com/");
exit();
}
?>
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="css/madscore.css">
</head>
<body>
</body>
</html>
Upvotes: 0
Reputation: 33996
You should send headers before your HTML page. Put your redirect code just before
<html> <head>
Regarding to this:
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
Upvotes: 6