Gilmore Posted November 25, 2006 Share Posted November 25, 2006 Hi all.I've just starting messing around with PHP and MySQL and just have a quick question.I'm playing around with a site that guy built for me a while ago and have set it up on my local machine. All seems to be going well so far but I am curious about one thing.How come this: [code]<? echo $_POST[fax] ?>[/code]works remotely, but locally I have to use the following:[code]<? echo $_POST['fax'] ?>[/code]Without the apostrophe on the variable I get [b]Notice: Use of undefined constant fax - assumed 'fax' in..[/b]Can anyone shed some light?Many thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/ Share on other sites More sharing options...
Psycho Posted November 25, 2006 Share Posted November 25, 2006 I believe that is due to a server configuration setting within the php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/#findComment-130108 Share on other sites More sharing options...
Gilmore Posted November 25, 2006 Author Share Posted November 25, 2006 OK thanks.Would you say that it's better to keep the apostrophe's or not? Or should I say, what's the best practice?Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/#findComment-130110 Share on other sites More sharing options...
wildteen88 Posted November 25, 2006 Share Posted November 25, 2006 Its because you are supposed to use apostrophes around associative arrays. Otherwise PHP thinks you're using a constant and thus you get a Notice message.Also it is not a configuration setting within the php.ini! Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/#findComment-130111 Share on other sites More sharing options...
Gilmore Posted November 25, 2006 Author Share Posted November 25, 2006 So how come the site works fine remotely without any error messages, but not locally? Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/#findComment-130112 Share on other sites More sharing options...
wildteen88 Posted November 25, 2006 Share Posted November 25, 2006 Your remote site is doing the same thing as what it does locally, except it doesn't show the notice message. Most probably because your host has disabled the display_errors directive or has set error_reporting directive to ignore notices.Also notices do not stop a script from running. Only error messages do.However as I did say in my last post you [b]should[/b] put apostrophes around associative indices. The only time you don't put apostrophises is when you use numerical indices. Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/#findComment-130116 Share on other sites More sharing options...
Gilmore Posted November 25, 2006 Author Share Posted November 25, 2006 OK great!Thanks for clearing that up. Quote Link to comment https://forums.phpfreaks.com/topic/28433-why-do-i-have-to-use-apostrophes-locally/#findComment-130117 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.