View Single Post

  #2 (permalink)  
Old 07-11-2003
Janwillem Borleffs
 
Posts: n/a
Default Re: Notice: Undefined variable: edit in.....


"Tim Dixon" <news@tdixon.com> wrote in message
news:3f0e6fcc$0$7730$fa0fcedb@lovejoy.zen.co.uk...
> Hi,
> I have some PHP code working fine on a web site.
> I have installed Apache web server on my local PC with PHP and mySQL
>
> It still works, but I get lots of errors like:
> Notice: Undefined variable: edit in C:\Program Files\Apache
> Group\Apache2\htdocs\schools\aenews.php on line 18
>
> In this particular case the code is:
>
> <? if ($edit == 'Y'){
> $result=mysql("$DBName","SELECT * FROM news WHERE..........
>
> If I lower the level of error reporting, the messages are removed (but I
> seem to think this is a false way to resolve the problem)
>


Keep the level as it is. The isset() function evals whether a variable is
set:

<? if (isset($edit) && $edit == 'Y'){...

> if I use ' ' arount the vatiable it seems to remove the problem too.
> ie:
> <? if ('$edit' == 'Y'){
> $result=mysql("$DBName","SELECT * FROM news WHERE..........
>
> So, can anyone tell the real reason for the error messages and why I need
> the ' ' marks?
>


When you are using single quotes, the expression is taken literal. With
double quotes the expression is parsed.

Example:

$greet = "Hallo";

echo '$greet'; // Displays $greet
echo "$greet"; // Displays Hallo
echo $greet; // Displays Hallo


JW



Reply With Quote