| re: Undefined variable error
On Sun, 13 Feb 2005 22:24:25 +0100, "Janwillem Borleffs"
<jw@jwscripts.com> wrote:
[color=blue]
>Martin wrote:[color=green]
>> This is copied straight out of a book I'm using to try to learn
>> about PHP and MySQL. Can someone tell me what's causing the
>> Undefined variable error? I didn't know that variables had to be
>> defined.
>>[/color]
>
>That's because you are concatenating the output from the function call with
>$db_list without it's initialized.
>
>Just initialize $db_list before you are using it and it'll work fine:
>
>$db_list = '';
>for ($row=0; $row < mysql_num_rows($rs); $row++) {
> $db_list .= mysql_tablename( $rs, $row ) . "<br>";
>}
>
>BTW, PHP will create variables on the fly, but throws notices when the error
>reporting level is high enough. There are ways of suppressing these errors
>without adjusting the error reporting level, but it's good programming
>practice to define the variables you're going to use.
>
>
>JW
>[/color]
Thanks.
One would think that the book's author should have known to do that. |