Why wont this work: '$_SERVER['PHP_AUTH_USER']'

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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Why wont this work: '$_SERVER['PHP_AUTH_USER']'

Post by nigma »

I am pretty sure I have to have the single qoutes around the text. Its for when I am inserting something into a database.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

then put double quotes around the single quotes

"This '$will' work"

'This $wont work'
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

And if it's in a SQL statement like:

Code: Select all

$sql = "SELECT this FROM that WHERE something = '$_SERVER['PHP_AUTH_USER']'";
you'll get a parse error, to make it work you need to have either:

Code: Select all

$sql = "SELECT this FROM that WHERE something = '$_SERVER[PHP_AUTH_USER]'";
or

Code: Select all

$sql = "SELECT this FROM that WHERE something = '{$_SERVER['PHP_AUTH_USER']}'";
or

Code: Select all

$sql = "SELECT this FROM that WHERE something = '".$_SERVER['PHP_AUTH_USER']."'";
So you can take your pick of syntax.

Mac
Post Reply