Page 1 of 1

Undefined variable error

Posted: Fri Feb 08, 2008 3:27 pm
by HakonHoy
I have just moved to a new Linux hosting with PHP and MySQL. At the last place I hosted the website I got no errors but here suddenly I got several errors:

"Notice: Undefined variable: news in /home/53/index.php on line 12"

Code: Select all

$sql="SELECT *, DATE_FORMAT(news_date, '%d.%m.%y') AS date FROM newstable, authortable WHERE newstable.news_authorid = authortable.author_id AND newstable.news_id = '$news'";
Why did I get that error in my new hosting and what is actually wrong? I'm not to good at Php :/

Here is another one:

Notice: Undefined variable: news_id in /home/53/index.php on line 4

Code: Select all

$sql = "SELECT * FROM cmt_table WHERE cmtnews_id = '$news_id' AND cmt_checked = '1' ORDER BY cmt_date DESC";

Re: Undefined variable error

Posted: Fri Feb 08, 2008 3:51 pm
by Christopher
The notices are telling you that the variables $news in the first and $news_id in the second have not been set to even a default value. You have something like $news = ''; and $news_id = 0; at the top of your script to remove the notices and as a good programming practice.

You can also set your error reporting to not show notices.

Re: Undefined variable error

Posted: Fri Feb 08, 2008 4:20 pm
by HakonHoy
What do you meen? I'm a noob :P

Re: Undefined variable error

Posted: Fri Feb 08, 2008 4:33 pm
by RobertGonzalez
If you were to code:

Code: Select all

<?php
echo $thisvariable;
?>
What would PHP put to the screen? How would it know the value of that variable?