include function in PHP 5

liunx

Guest
Hi !!

I'm newie in php.

This is my problem. I'm trying to do an aplication that use the include() fuction to read defined parameters. The problem is that when I try to use that fuction the browser don't display the info (or error or warning message), I think that I was doing something wrong but when put the script in PHP 4 it works fine !! :queasy:

Somebody knows what would be the problem, do I need change php.ini and what ?
The enviroment is this
PHP 5.0.4
Apache 2.0.54

Thanks
Blackwoodie

P.D
Sorry for the englishpost the relevant codeSorry I forgot to writte them, here they are :

This are the files

#####################
file: vars.inc

<?php
$welcome = 'Hello';
?>

#####################

file: index.php

<?php
include ("vars.inc");
echo ("$welcome");
?>

####################

That's all (just for testing purposes), any ideas ??

Thanks .. :)are these two files in the same directory?First I create a folder named "include" a put in there the file vars.inc, after it don't work I put them in the same directory with the same result :(your register globals is switched off in the php.ini, to make this work you need to do

global $welcome;

before you declare a value to it. this will then let you access it on other importing file.Er, no. register_globals has nothing to do with variable scope, and variable scope has nothing to do with whether the variables defined in "vars.inc" are visible in files it is included in.

Check php.ini; display_errors may be turned off. If it is, then switch it on; and while you're about it, you might as well set error reporting to E_ALL as that will help you develop some good programming habits (and leave register_globals turned off. It's nasty and PHP's developers are trying to get rid of it).I am also having this problem. I did not see an official resolution to this, thats why I'm posting on it.

setup:
winxp pro
apache 2.0.58
php 5.1.4
both files are in the htdocs folder
php display_errors is on

these are just the test pages...

index.php
<?php
include ('db_login.php');

$connection = mysql_connect($db_host, $db_username, $db_password) or
die ("Could not connect to the database: <br />". mysql_error());

echo "if you are reading this, you are connected!";
?>

db_login.php
<?php

$db_host = 'localhost';
$db_database = 'test';
$db_username = 'root';
$db_password = 'asdf';

<?

so with this current configuration, it returns a blank page
if I change the url from "db_login.php" to something non-existant, just for testing (like 1234.php), it says:

Could not connect to the database:
Access denied for user 'ODBC'@'localhost' (using password: NO)

if I erase the include() function all together, and set the variables within this document accordingly, it works.. and returns "if you are reading this, you are connected!"

what is going on? any help is appreciated!When I use the include statement I use the following (ie of connection):

include 'config.php';

/*** create a new database connection***/
$connection = mysqli_connect($hostname, $username, $password, $dbname) or die ("Unable to connect");



and my config.php file reads:



$hostname = 'localhost';

/*** mysql username ***/
$username = 'root';

/*** mysql password ***/
$password = 'special';

/*** mysql database name ***/
$dbname = 'test_sql';



I don't know if that helps, but this works every time for me.

Alol.. wow.. talk about TOTAL NOOBALISHOUS

so.. cause I read the forum sticky's I've been formatted my post to make it as readable as possible

the last change I did was to drop the <? down one line (on the db_login code quote so its not tacked on the end of the var)

thats when I noticed...

<? wtf???

changed to:

?>

worked.. what the hell am I smoking...
maybe I just need to post this on a forum to figure it out.. lol...
 
Back
Top