Conditional Redirect
Posted: Sun Mar 22, 2009 11:43 am
I want to have my page redirect to another page while a condition is true. Here is my code:
if($_POST[title] == 0 || $_POST[desc] == 0 || $_POST[name] == 0 || $_POST[email] == 0)
{
header("Location: http://www.google.com");
exit();
}
But I get this error:
Warning: Cannot modify header information - headers already sent by
I have looked at my PHP book and have found that whitespace before the php tags can be a problem, but I have opened it with several editors and have cleaned it up perfectly. I have looked at the line that the error returns and its at line 11, but at that line theres only the <?php tag. I have read online that I may be able to fix this problem by adding this to my configuration.php file:
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
But I do not have a configuration.php, and there should be an easier way to do this. Here is my complete coding:
</head>
<body>
<?php
$con = mysql_connect(x, x, x);
if(!$con)
{
die('Cannot connect: ' .mysql_error());
}
if($_POST[title] == 0 || $_POST[desc] == 0 || $_POST[name] == 0 || $_POST[email] == 0)
{
header("Location: http://www.google.com");
exit();
}
mysql_select_db("yourcol1_ITEM", $con);
$sql = ("INSERT INTO SELL (`title`, `desc`, `name`, `email`)
VALUES ('$_POST[title]','$_POST[desc]','$_POST[name]','$_POST[email]')");
if (!mysql_query($sql,$con))
{
die(mysql_error()."<br><br>$sql");
}
echo "Complete_debug";
mysql_close($con);
?>
</body>
</html>
(Ignore the 'x' marks in the code)
Foxy
if($_POST[title] == 0 || $_POST[desc] == 0 || $_POST[name] == 0 || $_POST[email] == 0)
{
header("Location: http://www.google.com");
exit();
}
But I get this error:
Warning: Cannot modify header information - headers already sent by
I have looked at my PHP book and have found that whitespace before the php tags can be a problem, but I have opened it with several editors and have cleaned it up perfectly. I have looked at the line that the error returns and its at line 11, but at that line theres only the <?php tag. I have read online that I may be able to fix this problem by adding this to my configuration.php file:
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
But I do not have a configuration.php, and there should be an easier way to do this. Here is my complete coding:
</head>
<body>
<?php
$con = mysql_connect(x, x, x);
if(!$con)
{
die('Cannot connect: ' .mysql_error());
}
if($_POST[title] == 0 || $_POST[desc] == 0 || $_POST[name] == 0 || $_POST[email] == 0)
{
header("Location: http://www.google.com");
exit();
}
mysql_select_db("yourcol1_ITEM", $con);
$sql = ("INSERT INTO SELL (`title`, `desc`, `name`, `email`)
VALUES ('$_POST[title]','$_POST[desc]','$_POST[name]','$_POST[email]')");
if (!mysql_query($sql,$con))
{
die(mysql_error()."<br><br>$sql");
}
echo "Complete_debug";
mysql_close($con);
?>
</body>
</html>
(Ignore the 'x' marks in the code)
Foxy