Page 1 of 1

variable won't display contents

Posted: Sat May 17, 2003 2:05 am
by jarow
$user = $_POST['username']


I have created a login redirect variable (within a php statement) which works if written this way:

$redirect = "admin_$user.php"

but does NOT work if I write it this way

$redirect = "$user_admin.php"

Why does username appear correctly in the first example but not in the second?

Many thanks

Jarow

Posted: Sat May 17, 2003 4:01 am
by twigletmac
Probably because PHP doesn't know where the variable ends - it doesn't know that you are trying to access $user, it probably thinks you are looking for $user_admin. (turn your error reporting up to E_ALL and you'll get notices about this sort of thing)

You can do:

Code: Select all

$redirect = $user.'_admin.php';
or

Code: Select all

$redirect = "{$user}_admin.php"
to make it explicit what variable you are looking for.

Mac