Page 1 of 1

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

Posted: Tue Jan 28, 2003 10:28 pm
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.

Posted: Tue Jan 28, 2003 11:24 pm
by hob_goblin
then put double quotes around the single quotes

"This '$will' work"

'This $wont work'

Posted: Wed Jan 29, 2003 2:27 am
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