Reputation: 57
This code below works perfectly fine when I try on my local host but when I upload it on to my server it does not work
$sendquery = "INSERT INTO `message` (`from`, `to`, `subject`, `date`,`message`) VALUES ('".$_SESSION['UID']."', '".$toarray['Uid']."', '$subject','$d', '$message')";
$sendresult = mysql_query($sendquery);
if($sendresult)
{
header('Location: home.php?action=inbox&success=1');
}
else
{
header("Location: home.php?action=inbox&success=2");
}
Is it a problem with my server or the code?
Upvotes: 1
Views: 7120
Reputation: 519
Check
var_dump($sendresult); exit();
Enable error reporting. You may have other error. By the way
$sendresult = 1;
if($sendresult) {
header('Location: home.php?action=inbox&success=1');
} else {
header("Location: home.php?action=inbox&success=2");
}
This works fine for me.
Upvotes: 0
Reputation: 5377
Make sure nothing in your code started output before you set the "Location" header.
Make sure you use an absolute URL (as required by the HTTP specification)
Sample:
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/Home.php');
If this is the case, your redirect should work.
Some common reasons why output already started:
<?php ... ?>
Upvotes: 1
Reputation: 662
Maybe you have an error in the SQL.
If you echo something (like an error message) you can't change the header anymore.
The header is send before the echo and setting the location after that has no effect.
Upvotes: 1
Reputation: 78941
The localhost and webserver have many differences together. I am guessing the problem to be developed on windows
and hosted on linux
.
Lowercase all the header string and stop the execution after it
header("location: home.php?action=inbox&success=2");
exit();
Upvotes: 0