variable won't display contents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

variable won't display contents

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply