1

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
Undefined index in PHP

Notice: Undefined index: NAME in C:\xampp\htdocs\pmsx\lib\config.php on line 107

That's the exact error. Here's my code on the file. Thanks for those will help.

here's my line 107:

//echo "<br>" . $cdata;
// create the proper tree node if NAME attribute is set
if ($this->attr["NAME"] != "")
    $this->tags[count($this->tags) - 1] = $this->attr["NAME"];

Pastie link

4
  • 2
    exactly what does this have to with sql at all? sounds more like a DOM operation. did you check if the node you're on HAS a NAME attribute? Commented Nov 26, 2012 at 20:20
  • Can you give the output of var_dump($this->attr); ? Commented Nov 26, 2012 at 20:21
  • fwiw, your second line can be simplified $this->tags[] = $this->attr["name"]; Commented Nov 26, 2012 at 20:25
  • @ScottEvernden, for what I can tell, the original line overwrites the last element, whereas yours adds. Though, it looks like the original line just has an error. Commented Nov 26, 2012 at 20:26

3 Answers 3

0

Use isset() first, to check, whether the property exists at all.

if ( isset( $this->attr["NAME"] ) && ($this->attr["NAME"] != "") ) {
    $this->tags[count($this->tags) - 1] = $this->attr["NAME"];
}

You error says, that the property NAME does not exist at all in the array attr!

Sign up to request clarification or add additional context in comments.

Comments

0

NAME isn't a defined index. You probably want:

if( isset($this->attr['NAME']) && $this->attr['NAME'] != "" ) {
    // ...

1 Comment

Funny. The post is edited by ComFreek. Are you related? ;-)
0

What you probably want is !empty($this->attr['NAME']) instead of $this->attr["NAME"]!="". Otherwise it errors out when NAME index is… well… undefined.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.