Another question from a newbie
Please tell me what statement I should use to go to another php page if a condition isnt met in an if statement.
I have used an include, but this includes the stuff on the previous page which I dont want.
Your help is greatly appreciated
Newbie
Forwarding to another page if a condition isnt met
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can use header():
Mac
Code: Select all
header('Location: http://www.mysite.com/someotherpage.php');header doesnt work
Hi Twigletmac
I tried your suggestion, but it doesnt seem to work: This is what I'm trying to do
$result = mysql_query($query) or
die (mysql_error());
if (mysql_num_rows($result) == 0)
{
header('../helpdesk/newuser/form.php');
}
else
When I run it, it still goes and processes the "else" even if the result is zero. I've tried making the "header" the else part of the statement and the same is true. Please help
I tried your suggestion, but it doesnt seem to work: This is what I'm trying to do
$result = mysql_query($query) or
die (mysql_error());
if (mysql_num_rows($result) == 0)
{
header('../helpdesk/newuser/form.php');
}
else
When I run it, it still goes and processes the "else" even if the result is zero. I've tried making the "header" the else part of the statement and the same is true. Please help
You have to include "Location"
so it would look like
that should work. remember to keep the "Location:" part in there. And for security reasons you can include exit();
so it would look like
Code: Select all
header('Location: www.go.com');
exit();- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
As net7 said, you do need the 'Location: ' bit and you also need to read the manual page for the header() function:
Mac
There's an example on the page of how to do this.PHP Manual wrote:Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself.
Mac