0

I'm querying a DB but for reasons unbeknownst to me I keep getting undefined index.

The Undefined index it's referring to IS in the DB and everything IS spelld correctly. (I've checked & re-checked) yet still undefined index.

As part of my diagnosis I changed it from $variable['index'] to $ariable['index'] and I get an undefined variable so I know the variable works.

Additionally, I am selecting * in the query behind $variable yet I'm still getting the undefined index.

If anyone could set me straight on what's happening I'd be most appreciative and I thank you in advance.

Sebas
  • 21,192
  • 9
  • 55
  • 109
  • Are you getting a php error or a mysql error? Please post some code – Sam Dufel Jun 05 '13 at 23:49
  • 7
    Could you provide some code? We aren' t that good with guessing :) – DAG Jun 05 '13 at 23:49
  • Can you post a copy of the code your using? – Dracs Jun 05 '13 at 23:49
  • @TimothyChoi That's the first-use-then-investigate function in php :D (unless your working with circular objects of course) – PHP lover Jun 05 '13 at 23:54
  • You may try to restart/ recreate database. Sometimes it runs into different bugs, and you have to recreate it. Once I've had a bug, that it said that `table doesn't exist`, but I couldn't create it(because of `such table already exists`) – therealszaka Jun 06 '13 at 00:06
  • I'll try to get some code up soon –  Jun 06 '13 at 00:15
  • @PHPlover Also good for variable analysis. – tyteen4a03 Jun 06 '13 at 00:17
  • @Stuart Kaufman My guess is that you're fetching the data as a numeric array instead of associative array – PHP lover Jun 06 '13 at 00:23
  • table names are case insensitive, fieldnames are case-sensitive –  Jun 06 '13 at 00:27
  • Some blind guesses are (1) not fetching a result row and trying to index into the result resource, or (2) fetching a row with `mysql_fetch_row` instead of `mysql_fetch_array`. In either case, `print_r($variable)` or `var_dump($variable)` will help you. – jcsanyi Jun 06 '13 at 04:13
  • possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Jocelyn Jun 06 '13 at 08:00

1 Answers1

1

index is a reserved word in MySQL. If an identifier contains a reserved word, you must quote it whenever you refer to it.

david strachan
  • 7,174
  • 2
  • 23
  • 33