|
Redirect before mysql insert.. but after submit
This is a form of error handling. I can't seem to get it to work.
PHP Code:
<?php
$path = $_SERVER['PHP_SELF'];
$path_parts = pathinfo($path);
$string = $path_parts["basename"];
$exclude = ".jpg.php";
$path = substr("$string",0,strpos($string,$exclude));
echo "Image: $path ";
if(isset($_POST['submit'])) {
$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
$query = "SELECT last_ip FROM photographs WHERE name=$path";
if ($query = $ip) {
header("Location: error.php");
}
$link = mysql_connect('localhost', 'andrew', '1357908642');
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('andrew_site', $link);
$message = stripslashes(trim($message));
$message = nl2br($message);
$message = htmlentities($message);
$query = "INSERT INTO photos (ip, comment, photo)
VALUES ('$ip', '$message', '$path')";
mysql_query($query);
mysql_close();
echo "Thanks $name your comment has been added";
}
?>
You can see the part that is wrong
PHP Code:
if ($query = $ip) {
header("Location: error.php");
}
Headers can't be sent after submit has been made.. How can I redirect if it's wrong?
|