Can't seem to get it right with the syntax:
<?php
if isset $_POST['tutorial'] {
header('Location: /phonebooks?tutorial=1b');
} else {
header('Location: /phonebooks?phonebook_created=1');
};
?>
What am I doing wrong??
Can't seem to get it right with the syntax:
<?php
if isset $_POST['tutorial'] {
header('Location: /phonebooks?tutorial=1b');
} else {
header('Location: /phonebooks?phonebook_created=1');
};
?>
What am I doing wrong??
You're missing brackets around your if condition and around $_POST['tutorial']
, which is an argument to isset
. It should be:
<?php
if (isset($_POST['tutorial']))
{
header('Location: /phonebooks?tutorial=1b');
}
else
{
header('Location: /phonebooks?phonebook_created=1');
}
?>
As pointed out in the comments, an absolute URL is required for a Location
header as well (so instead of /phonebooks?tutorial=1b
, you'd need to specify http(s)://yourdomain.com/phonebooks?tutorial=1b
).
Ok, first off, you need to use parenthesis. Multiple parenthesis.
The first set need to go around the contents of the if construct:
if ( ... ) {
The second set need to go around the isset()
function call:
isset($_POST['tutorial'])
So that line becomes:
if (isset($_POST['tutorial'])) {
You also have another problem. Don't use location headers with relative urls. It's against the HTTP specification. Always use absolute URLs, otherwise you may break some webservers (I know IIS hates it), or browsers...