By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

variable in include

P: n/a
HI all,
Weird problem....

in the file queries.inc.php I've this:
$query = 'select * from list where content = '.$idcontent;

I've this code in my page:
$idcontent = 15;
require_once("queries.inc.php");

The query fails: when I do echo the query I've:

select * from list where content =

The $idcontent isn't set in the include...why ? how to fix it ?

May 10 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On May 10, 4:33 pm, "Bob Bedford" <b...@bedford.comwrote:
HI all,
Weird problem....

in the file queries.inc.php I've this:
$query = 'select * from list where content = '.$idcontent;

I've this code in my page:
$idcontent = 15;
require_once("queries.inc.php");

The query fails: when I do echo the query I've:

select * from list where content =

The $idcontent isn't set in the include...why ? how to fix it ?
actually use an include_once (rather than require)

May 10 '07 #2

P: n/a
On May 10, 4:33 pm, "Bob Bedford" <b...@bedford.comwrote:
HI all,
Weird problem....

in the file queries.inc.php I've this:
$query = 'select * from list where content = '.$idcontent;

I've this code in my page:
$idcontent = 15;
require_once("queries.inc.php");

The query fails: when I do echo the query I've:

select * from list where content =

The $idcontent isn't set in the include...why ? how to fix it ?

Sounds like the var $idcontent is actually null rather than it being
an include problem. Try echoing that var on the include page and
running it on its own

Ciarán

May 10 '07 #3

P: n/a
Sounds like the var $idcontent is actually null rather than it being
an include problem. Try echoing that var on the include page and
running it on its own

Ciarán
Sorry- my mistake I didnt notice you've defined the var in the page
itself. I do this exact thing on a bunch of pages and it works fine. I
use a require_once just like you too. Are you running an old version
of PHP or something maybe?

sorry i know I'm not being much help but it all looks good to me!

May 10 '07 #4

P: n/a
Sorry- my mistake I didnt notice you've defined the var in the page
itself. I do this exact thing on a bunch of pages and it works fine. I
use a require_once just like you too. Are you running an old version
of PHP or something maybe?

Thanks for your reply. I use PHP 4.4.1
May 10 '07 #5

P: n/a

"David Gillen" <Be****@RedBrick.DCU.IEa écrit dans le message de news:
sl*******************@murphy.redbrick.dcu.ie...
Bob Bedford said:
>HI all,
Weird problem....

in the file queries.inc.php I've this:
$query = 'select * from list where content = '.$idcontent;

I've this code in my page:
$idcontent = 15;
require_once("queries.inc.php");

The query fails: when I do echo the query I've:

select * from list where content =

The $idcontent isn't set in the include...why ? how to fix it ?
Is your $query = .. line inside of function in teh queries.inc.php?
If so $idcontent is out of scope.
NO it's not....
I've also tried to define the idcontent var as global again in the
queries.inc.php but it doesn't work either.
May 10 '07 #6

P: n/a
If you define a variable $x and then INCLUDE a file such as
include_once("path"); it should work.

So if you have:

$query = 'select * from list where content = '.$idcontent;

And

$idcontent = 15;
require_once("queries.inc.php");

You need to change require to include.

so it should be

$idcontent = 15;
include_once("queries.inc.php");

And you can check this by doing something like

if ( $idcontent 0 ) {

}

May 10 '07 #7

P: n/a
On May 10, 2:59 pm, SterLo <sterling.hamil...@gmail.comwrote:
If you define a variable $x and then INCLUDE a file such as
include_once("path"); it should work.

So if you have:

$query = 'select * from list where content = '.$idcontent;

And

$idcontent = 15;
require_once("queries.inc.php");

You need to change require to include.

so it should be

$idcontent = 15;
include_once("queries.inc.php");

And you can check this by doing something like

if ( $idcontent 0 ) {

}
Not true -- require and include behave identically in every way except
for what happens when the file cannot be included for some reason.

<http://www.php.net/require>

May 10 '07 #8

P: n/a
Bob Bedford kirjoitti:
HI all,
Weird problem....

in the file queries.inc.php I've this:
$query = 'select * from list where content = '.$idcontent;

I've this code in my page:
$idcontent = 15;
require_once("queries.inc.php");

The query fails: when I do echo the query I've:

select * from list where content =

The $idcontent isn't set in the include...why ? how to fix it ?
Just as a sanity test:
<?php
$foo ='bar';
require_once('echo.php');
?>

echo.php:
<?php echo $foo; ?>

Does the simplest possible test case like the one above work? If it
works, then the problem is not in including, but somewhere else. If it
doesn't, the latest version of php 4 is 4.4.7, you should upgrade to
that if there indeed is a problem related to passing variables to
included pages, which I highly doubt.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 10 '07 #9

P: n/a
Bob Bedford wrote:
HI all,
Weird problem....

in the file queries.inc.php I've this:
$query = 'select * from list where content = '.$idcontent;

I've this code in my page:
$idcontent = 15;
require_once("queries.inc.php");

The query fails: when I do echo the query I've:

select * from list where content =

The $idcontent isn't set in the include...why ? how to fix it ?
Hi Bob,

away from all prior given replies I strongly suggest you to review your
programming style. Use a less a possible global variables in your code.
Don't be anger with me, I just want to give you food for thought.

hth,
Roy
May 11 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.