Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP Includes

Newbie
 
Join Date: Mar 2008
Posts: 1
#1: Mar 16 '08
Hey,

I'm relatively new to PHP. I have programmed in C++ and JavaScript before.

I have this piece of code that writes a value to a file.
[PHP]$myFile = "minval.php";
$fh = fopen($myFile, 'w') or die("can't open file");;
fwrite($fh, $minval);
fclose($fh);[/PHP]

The $minval is user defined and is an integer.

Anyways, after I try to include the "minval.php" like this:
[PHP]$order = include('minval.php');[/PHP]

The minimum value is always 1 (because include() returns 1). I want it to return the value inside of minval.php, not 1.

Anyone know how to do it?

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 16 '08

re: PHP Includes


If you want to include it, you must write the variable name inside, in an assign statement, like [php]fwrite($fh, '$order='.$minval.';');[/php]

Then you do not assign the included file, but just do the include[php]include('minval.php');[/php]Then the variable $order is available.

Ronald
Reply