Short Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Short Question

Post 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'
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

do you mean

if ($var == something){
echo "do something"
}
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post 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';
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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
}
?>
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post by pido »

Ooouuww.... now i got it !! thnx guys, you all my idols :o
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post 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 ??
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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:
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

you have to change error_reporting in php.ini
User avatar
pido
Forum Commoner
Posts: 35
Joined: Mon Jan 12, 2004 8:03 am

Post by pido »

thnx guys... i really appreciate ur help, in my language i would say "ma' kasih banget..." :D
Post Reply