2
Notice: Use of undefined constant username - assumed 'username' in
/home/content/04/7195304/html/header.php on line 54

I get this when writing things like $_COOKIE[username] or $_POST[username].

Edit

So I've been playing around with the code, putting quotes in my POST, COOKIE, and GET's.. I still get the same thing!

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Seth
  • 2,043
  • 5
  • 20
  • 23
  • 1
    Technically, it is not an error. But you should fix it anyway! – Felix Kling Feb 25 '11 at 23:55
  • Is this still a problem? If so, you should add the code of the line which is mentioned in the error message (and maybe some lines around it). (If it is solved, you should instead accept the answer which most helped, or add an own answer instead.) – Paŭlo Ebermann Sep 01 '11 at 00:50
  • See also [my attempt at a canonical answer for causes of this error message](http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean/8025500#8025500). – John Carter Nov 06 '11 at 06:36

3 Answers3

6

It means you likely forgot a $ in front of your variable name.

Edit You need to encapsulate your call in qoutes. I.e.

$_COOKIE["username"]

or

$_POST["username"]
dmcnelis
  • 2,913
  • 1
  • 19
  • 28
3

It probably means you forgot to put a $ in front of your username variable, so it's treating it like a constant instead of a variable.

You should post the code from that line for better help.

Anthony
  • 36,459
  • 25
  • 97
  • 163
  • Ah. The code helps. You didn't put quotes around your array keys. Try `$_COOKIE['username']` – Anthony Feb 25 '11 at 23:46
  • Can you copy line 52 - 56 of the actual file? – Anthony Feb 25 '11 at 23:52
  • Hm. Well, actually, I've been playing around with the code, so that no longer matters. I keep getting errors like 'Notice: Undefined index: register in /home/content/04/7195304/html/index.php on line 19'.. Line 19 is if ($_POST['register']) { – Seth Feb 25 '11 at 23:55
  • 2
    Well, a notice isn't an error. If I say `echo $_POST['foo']` and I don't have that in my array, it would give that notice. If you want to avoid it, you probably want to do `if(isset($_POST['register'])) {` – Anthony Feb 26 '11 at 00:02
1

You might as well try $_COOKIE['username'] or $_POST['username'], to access the associative arrays with a string.

Sorry, overlooked comment with same advice.

Nick Weaver
  • 47,228
  • 12
  • 98
  • 108