General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 14th, 2002, 11:03 AM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
What the hell!?

I *keep* getting stupid errors like this, and I've no idea what's causing them. Am I following some bad coding practice? Anyway, the error is as follows:

Quote:
Notice: Use of undefined constant simon - assumed 'simon' in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 2
simon


The actual code of that page is only this:

PHP Code:
<?php
$username
=simon;
echo 
$username;
?>


Unless I'm really dumb, I can't see a problem with it.

I'm using Apache 2.0.4.3, PHP 4.30RC3

It happens no matter what variable I declare etc, so any help would be massively appreciated (as this is causing problems in any frickin script I write)

Reply With Quote
  #2  
Old December 14th, 2002, 11:35 AM
Brian Rosner Brian Rosner is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Denver, CO
Posts: 34 Brian Rosner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Brian Rosner Send a message via AIM to Brian Rosner Send a message via Yahoo to Brian Rosner
Re: What the hell!?

Quote:
Originally posted by Kanu
I *keep* getting stupid errors like this, and I've no idea what's causing them. Am I following some bad coding practice? Anyway, the error is as follows:



The actual code of that page is only this:

PHP Code:
<?php
$username
=simon;
echo 
$username;
?>


Unless I'm really dumb, I can't see a problem with it.

I'm using Apache 2.0.4.3, PHP 4.30RC3

It happens no matter what variable I declare etc, so any help would be massively appreciated (as this is causing problems in any frickin script I write)


Looks like PHP is seeing simon as a constant. First off, you never defined the constant if that's what you intented. Or if you want the username to be simon it should be $username="simon"; to define a constant

PHP Code:
 define('SIMON','valueofconstant'); 


All constants should be upper, but you can get around that.

Reply With Quote
  #3  
Old December 14th, 2002, 02:01 PM
Kanu Kanu is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 91 Kanu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Well, hrm, I don't want it to be a constant, it should be variable, though doesn't PHP work such that:
PHP Code:
 $somevariable=somevalue

works such that if the variable does exist, it is assigned the value, and if it doesn't, it is initialised and then assigned the value? If that's so, I shouldn't be getting errors from that code, right?

Reply With Quote
  #4  
Old December 14th, 2002, 03:44 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
Quote:
Originally posted by Kanu
Well, hrm, I don't want it to be a constant, it should be variable, though doesn't PHP work such that:
PHP Code:
 $somevariable=somevalue

works such that if the variable does exist, it is assigned the value, and if it doesn't, it is initialised and then assigned the value? If that's so, I shouldn't be getting errors from that code, right?

Surround the value of the variable in quotes ->

$somevariable = 'somevalue';

Without quotes php will think you are asigning the value of a constant to that variable.....
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #5  
Old December 15th, 2002, 08:06 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
if you asign a string to a variable it MUST be encase in quotes otherwise PHP things the string is a constant.

Reply With Quote
  #6  
Old December 15th, 2002, 10:19 PM
Isaac Isaac is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: pants.
Posts: 7 Isaac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Isaac Send a message via Yahoo to Isaac
Is there an echo in here?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > What the hell!?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT