bruno
asked on
undefined variable error
Hi,
I am trying to convert a site from ASP to PHP, and I found some code that I am trying to use here:
http://www.blinding-light.com/tutorials.php?page=read&id=7
THis code accomplishes something very similar to what I was doing in ASP with server.execute
However, I am getting an error that:
Notice: Undefined variable: page in D:\web\v4.0\include.php on line 4
do i have to do something to define the variable like you do in ASP? dimming or the such?
thanks,
bruno
I am trying to convert a site from ASP to PHP, and I found some code that I am trying to use here:
http://www.blinding-light.com/tutorials.php?page=read&id=7
THis code accomplishes something very similar to what I was doing in ASP with server.execute
However, I am getting an error that:
Notice: Undefined variable: page in D:\web\v4.0\include.php on line 4
do i have to do something to define the variable like you do in ASP? dimming or the such?
thanks,
bruno
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
inq123,
did you look at the URL i posted?
peyox,
let me give that a shot...
did you look at the URL i posted?
peyox,
let me give that a shot...
ASKER
peyox,
that seems to have gotten rid of the error....can you explain to me what that line does, piece by piece?
I see it obviously sets the variable $page to whatever the page querystring is - but i'm not quite sure i understand all the syntax.
thanks
that seems to have gotten rid of the error....can you explain to me what that line does, piece by piece?
I see it obviously sets the variable $page to whatever the page querystring is - but i'm not quite sure i understand all the syntax.
thanks
ASKER
oh btw...
>>(unless you deliberately set warning level high).
i haven't deliberately done anything - i used the default windows installer (i realize this is not recommended, but i am still a newbie)
>>(unless you deliberately set warning level high).
i haven't deliberately done anything - i used the default windows installer (i realize this is not recommended, but i am still a newbie)
$page = isset($_GET['page']) ? $_GET['page'] : "";
is equal to:
if (isset($_GET['page']))
$page = $_GET['page'];
else
$page= "";
It cheks if variable 'page' is set in query string. If so, it assigns 'page' value from query string to $page variable, otherwise it sets empty string $page="";
Since register_globals (see: http://us3.php.net/register_globals) is OFF by default, variables from query string are not declared and you have to "declare" them ($page=$_GET['page']) manually or use $_GET[] directly.
Hope this helps
peyox
is equal to:
if (isset($_GET['page']))
$page = $_GET['page'];
else
$page= "";
It cheks if variable 'page' is set in query string. If so, it assigns 'page' value from query string to $page variable, otherwise it sets empty string $page="";
Since register_globals (see: http://us3.php.net/register_globals) is OFF by default, variables from query string are not declared and you have to "declare" them ($page=$_GET['page']) manually or use $_GET[] directly.
Hope this helps
peyox
ASKER
that helps a lot, thank you.
one last question if you don't mind while i have you?
if i declare the page variable in an include file, should i be able to use that within another include file?
tks,
bruno
(upped points)
one last question if you don't mind while i have you?
if i declare the page variable in an include file, should i be able to use that within another include file?
tks,
bruno
(upped points)
The answer is yes.
a.php
<?
include "b.php";
echo $b;
?>
b.php:
<?
$b = 5;
?>
a.php will produce otput:
5
a.php
<?
include "b.php";
echo $b;
?>
b.php:
<?
$b = 5;
?>
a.php will produce otput:
5
ASKER
ah nevermind that last question it seems that i can once i fixed an issue i overlooked
ASKER
ah you already answered anyway. :-) thanks.
No, you don't need to declare the variable or even defining the variable (unless you deliberately set warning level high).
You need to show us the script for us to diagnose it for you.
Cheers!