1

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

I am new to PHP and mySQL and this is a section of my program, but what happens is that it doesn't return the value of the column 'Text' from the database, rather, it says 'Undefined index 'Text''. I am 100% sure that it exists in the database. Can someone please help me?

$method_get_article = "SELECT TEXT FROM ARTICLE WHERE UID = '$user_id' LIMIT 1";
$get_article = mysql_query($method_get_article, $conn) or die (mysql_error());
$article = mysql_fetch_array($get_article);**strong text**
$text = $article['Text'];
//$row = mysql_fetch_assoc($get_article);
//$text = $row['Text'];
echo $text;
Community
  • 1
  • 1
Blimeo
  • 295
  • 2
  • 3
  • 10
  • 3
    It may not help answer your question, but you should stop using `mysql_*` functions. They're being deprecated. Instead use [PDO](http://php.net/manual/en/book.pdo.php) (supported as of PHP 5.1) or [mysqli](http://php.net/manual/en/book.mysqli.php) (supported as of PHP 4.1). If you're not sure which one to use, [read this article](http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/). – Matt Aug 16 '12 at 15:13
  • 3
    dont use reserved words for fields BUT if you must use ` quotes around them – Waygood Aug 16 '12 at 15:13
  • perform a `var_dump()` on `$article` and see what it produces. – Matt Aug 16 '12 at 15:14
  • try `$text = $article['TEXT'];` – John Woo Aug 16 '12 at 15:15
  • var_dump($article); to double check – Waygood Aug 16 '12 at 15:18
  • @Waygood Although you are right, `TEXT` does not strictly need backticks, http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html (or any other version of the manual) – jeroen Aug 16 '12 at 15:19

1 Answers1

2

The error explains the problem very clearly : 'Undefined index 'Text'

In the beginning you write:

$method_get_article = "SELECT TEXT FROM ARTICLE WHERE UID = '$user_id' LIMIT 1";

which means you select the column called "TEXT", and then later you write:

$text = $article['Text'];

which gets the column called "Text".

Change them so that they are identical.

DannyCruzeira
  • 564
  • 1
  • 6
  • 19