Page 1 of 1

Short Question

Posted: Sun Jan 18, 2004 6:08 am
by pido
Ok first of all im new in php and i just want to ask why if i put code

Code: Select all

if ($var){
  echo "Do sumthing";
}
it give me an error message like this
Notice: Undefined variable: error in path/file.php on line 43

plz explain to me, why ?!? should i declare that variable first be4 using it ?? eventhough it give me an error the script still run... 8O
and just for note i set register_global to 'ON'

Posted: Sun Jan 18, 2004 6:11 am
by malcolmboston
do you mean

if ($var == something){
echo "do something"
}

Posted: Sun Jan 18, 2004 6:32 am
by pido
nope its

Code: Select all

if ($var){
  echo "do sumthin";
}
ok if i want to put it that way should i declare the variable first to

Code: Select all

$var = 0';

Posted: Sun Jan 18, 2004 6:56 am
by fastfingertips
I think that if you do not declare the variable the variable is just a memory zone and nothing inside, so you cannot compare it with something.

Posted: Sun Jan 18, 2004 7:04 am
by vigge89

Code: Select all

<?php
if ($var) {
//do something
}
?>
would mean:
if $var equals to true, do something, so you have to set $var to either true or false before doing this.

some examples:

Code: Select all

<?php
if ($var == "something") {
//if var equals to "something", do something
}
?>

Code: Select all

<?php
if ($var = "something") {
//if php succesfully set $var to "something", do something
}
?>

Posted: Sun Jan 18, 2004 8:43 am
by pido
Ooouuww.... now i got it !! thnx guys, you all my idols :o

Posted: Sun Jan 18, 2004 9:12 am
by pido
ok another question, i duno how to ask this question in appropiate PHP language, well....

how u configure the apache server, i mean the general configuration for apache server especially in error reports, cuz i always get error reports in page for variables but the variables is displayed.

it always like "Undefined variable :", should i change sumthing in configuration for apache server ??

Posted: Sun Jan 18, 2004 9:21 am
by qads
that has noting to do with apache, thats php, you can remove the notices/errors by editing your php.ini file, it should be in c:/windows/php.ini, if not, use phpinfo(); in a php page to see where it is,
open it with notepad and search for

error_reporting = E_ALL

then replace it with:

error_reporting = E_ALL & ~E_NOTICE

that should fix it.

dont forgot to restart apache after you save php.ini :wink:

Posted: Sun Jan 18, 2004 9:23 am
by AVATAr
you have to change error_reporting in php.ini

Posted: Mon Jan 19, 2004 5:31 am
by pido
thnx guys... i really appreciate ur help, in my language i would say "ma' kasih banget..." :D