Page 1 of 1

Auto forwarding using variables

Posted: Thu Apr 02, 2009 7:03 am
by WayneG
Hi.
I have a form file, which after submission, goes to a "process" file.
I want to use some code at the end of the process file to forward to another page, depending on what the "match_no" is.
Code:
echo '<META HTTP-EQUIV="Refresh" Content="1;
URL=cards/match_no'$match_no'-mailer.php">';
exit;
The error message says "Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' "

I have tried putting the ";" in various places with no luck.
Can anyone suggest what is wrong?
Thanks,
Wayne.

Re: Auto forwarding using variables

Posted: Thu Apr 02, 2009 7:26 am
by Apollo
You are either concatenating strings incorrectly, or you are using the wrong kind of string to include $match_no.

$variables inside strings are only parsed by PHP in double quoted strings. You are echo'ing a single quoted string.
Concatenation of strings is done with the . operator.

Try this instead:

Code: Select all

echo "<META HTTP-EQUIV='Refresh' Content='1; URL=cards/match_no$match_no-mailer.php'>";
(note that I changed the quotes inside the string to single quotes, otherwise you have to escape them to notify they don't mean the end of the whole string).

See also the PHP String reference.

Or use concatenation (which you probably intended) but don't forget the dots before and after $match_no:

Code: Select all

echo '<META HTTP-EQUIV="Refresh" Content="1; URL=cards/match_no'.$match_no.'-mailer.php">';

Re: Auto forwarding using variables

Posted: Thu Apr 02, 2009 9:05 am
by WayneG
Excellent.
Thank you.