require_once

I have a php file vraag.php with the following code :

[php]require_once("…/.common/.init.php");

$db = new PDO(DBASE);

$result = $db->query(‘SELECT * FROM Vraag ORDER BY id DESC’);
foreach($result as $row)
{
extract($row);
if ($status == $statuscode)
{$lid=$lidnr;}

[/php]

the .init.php file contains $statuscode = “1234”;

but if i check the value of $statuscode in vraag.php it has the value of 0.

how come?

actually it has no value at all.

I understand what you’re saying, but without seeing the .init.php code, it’s hard to say why.

If $statuscode is defined inside of a function in .lnit.php, I can see it having no value…

Yes, as Topcoder said if it’s in a function or class or, if the require failed or if your extract() call is overwriting it (but you say it has no value so it’s probably not defined). First step:
[php]error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

init.php :

[php]define(“DBASE”,“sqlite:…/…/sqlite/Polderlaan_Db.sqlite”);

$lidtekst = “Mee doen?
Eerst (gratis) inschrijven in de winkel, al 1400 mensen gingen u voor!”;
$statuscode = “1234”;

$status_ip1 = ‘81.207.85.59’;
$status_ip2 = ‘82.170.226.35’;
$status_ip3 = ‘82.197.211.115’;

$sitebkground = “#87CEFA”;
$menuback = “#FFFFFF”;
$topbkground = “#4B259C”;

$input = “White”;
$formbkground = “Lightgrey”;

$frground = “Darkblue”;
$bkground = “#FFFFFF”;

$itewidth = 1010; //980
$iteheight= 780;

$itewidth13= intval($itewidth/4);
$itewidth23= intval($itewidth13*2);
$itewidth34= $itewidth23 + $itewidth13;
$titelwidth= $itewidth13 - 2;

$v1color = “Silver”;
$v2color = “E5097F”;
$v3color = “00A0E3”;
[/php]

above define import_request_variables(gp);

i have a file : nwspul.php with a link <a href='nwspul_big.php?id=$id' target= '_top'>

nwspul_big.php : .......<p style='position: absolute; margin-top: 150; margin-left: 240; color: White' title='Let op!'>$lidtekst</p>.......

in this file $lidtekst and $statuscode of init.php is well recognized.
As you can see if you click on a picture at : kwikweb.nl/paginas/indexbody.php you see $lidtekst

So you turned on error reporting and there are no warnings or notices?

yes it says:

Notice: Undefined variable: statuscode

Do you know why I getting this error ?

Can you re-post your code showing the error reporting turned on. If I was to guess, I would say your require_once is failing because the path is wrong.

You can test that by adding this to the beginning of your init.php…

[php]echo ‘this is a test’;
exit;[/php]

If you don’t see that printed to your screen, then you know the require_once path is failing.

Yes it is printed!

But the define(“DBASE”,“sqlite:…/…/sqlite/Polderlaan_Db.sqlite”); in init.php works well !

And as I said if you click on a picture <a href='nwspul_big.php?id=$id' target= '_top'> than $statuscode is defined well, very strange.

[php]$result = $db->query(‘SELECT * FROM Vraag ORDER BY id DESC’);
foreach($result as $row)
{
extract($row);
echo “test: $statuscode”;
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
}[/php]

I believe @abracadaver wanted you to add

[php]error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

At the very top of your php file, not in the foreach loop.

Than I get the same Notice !

If I put $statuscode in the indexbody.php it works.

The problem could be using the heredoc syntax :

indexbody:

[php]require_once("…/.common/.init.php");

$style = ‘…/.common/default.css’;
$ip = $_SERVER[‘REMOTE_ADDR’];
if ($ip != $status_ip1 and $ip != $status_ip2 and $ip != $status_ip3) {$status = ‘sorry’;}

$db = new PDO(DBASE);
$result = $db->query(“SELECT * FROM Teksten WHERE soort=‘adres’;”);
foreach($result as $row)
{ extract($row); $adres = $tekst;}

$telefoon = ‘Vragen? Bel ons! (dinsdag t/m vrijdag tussen 10 en 16 uur)’;
$nwsbrief = “…/nieuwsbrief/print.php”;
$omschrijvingRW = <<< OMSCHR
Bij de Ruilwinkel helpen we elkaar met spullen en diensten.
De waardering gaat in punten, geld speelt geen rol.
U kunt punten verdienen door andere deelnemers te helpen, met spullen die u zelf over hebt, of door een klusje op te knappen.
Met de verdiende punten kunt u zelf spullen afnemen of hulp vragen bij dingen waar u zelf minder goed in bent.
Dankzij de punten is ruilen met gelijk oversteken niet nodig!
OMSCHR;

$setServTitel = ‘setServTitel’;

function setServTitel() {

if(!isset($_GET['service']))
	$_GET['service'] = "Spulaanbod";

switch($_GET['service'])
{
case "Spulaanbod": return "<h2>Spullen Aangeboden</h2>";break;
case "Spulgevraagd": return "<h2>Spullen Gevraagd</h2>";break;
case "Hulpaanbod": return "<h2>Hulp Aangeboden</h2>";break;
case "Hulpgevraagd": return "<h2>Hulp Gevraagd</h2>";break;
case "Leenaanbod": return "<h2>Te Leen Aangeboden</h2>";break;
case "Info": return "<h2>Info</h2>";break;
}

}

$setService = ‘setService’;

function setService() {

ob_start();

switch($_GET['service'])
{
case "Spulaanbod": include '../paginas/nwspul.php';break;
case "Spulgevraagd": include'../paginas/vraag.php';break;
case "Leenaanbod": include '../paginas/uitleen.php';break;


}
$include = ob_get_contents();
ob_end_clean();
return $include;

}

$menu = <<< MENU

MENU;

echo <<< BODY

Test
010-2151657
$adres
$menu

{$setServTitel()}

{$setService()}

{$setServTitel()}

$menu
Copyright © 2013 Fijenoord Ruilwinkel
BODY;[/php]

It’s interesting, but that shouldn’t cause it not to work…

Whats the difference between the vraag.php and index.php? The seem to look very similar from the first couple of lines…

If you echo

 echo "test: $statuscode"; 

Before the extract statement on vraag.php what happens?

I already tried. I also tried an empty vraag.php with echo “test: $statuscode”. So I think this could be the problem:

[php]$setService = ‘setService’;

function setService() {

ob_start();

switch($_GET['service'])
{
case "Spulaanbod": include '../paginas/nwspul.php';break;
case "Spulgevraagd": include'../paginas/vraag.php';break;
case "Leenaanbod": include '../paginas/uitleen.php';break;


}
$include = ob_get_contents();
ob_end_clean();
return $include;

}[/php]

isn’t it ?

I believe so.

I was testing and I changed the indexbody.php like this :

[code]

010-2151657
$adres
$menu

{$setServTitel()}

BODY;

echo “

”;include’…/paginas/vraag.php’; “
”;
echo <<< TEST

{$setServTitel()}

$menu
Copyright © 2013 Fijenoord Ruilwinkel
TEST; ?>[/code]

Now the $statuscode works as you can see on the website : http://kwikweb.nl/paginas/indexbody.php?service=Spulgevraagd but the problem is you see two containers in IE and in Chrome you see extra white space under the horizontal scrollbar!

But if i replace the include with the function :

[php]function setService() {

switch($_GET['service'])
{
case "Spulaanbod": include '../paginas/nwspul.php';break;
case "Spulgevraagd": include'../paginas/vraag.php';break;
case "Leenaanbod": include '../paginas/uitleen.php';break;


}

}[/php]

it doesn’t work! It looks like it’s a function problem ?

This should address the style problem, you just got the div’s in the wrong spot

[php]

010-2151657
$adres
$menu

{$setServTitel()}

BODY;

echo “

”;include’…/paginas/vraag.php’; “
”;
echo <<< TEST

{$setServTitel()}

$menu
Copyright © 2013 Fijenoord Ruilwinkel
TEST; ?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service