A file is included in PHP, but the variable is Undefined

I am new to PHP and I started using XAMPP to build the site. I have the code below

db.php:

<?php
    $hostName='localhost';
    $userName='xxxxxxxxx';
    $userPass='xxxxxxxxx';
?>

and test.php:

<?php
    include 'db.php';
    echo $hostName;
?>

but now it shows me Note: Undefined variable: hostName

I found that register_globals needs to be set to "on" in php.ini, but after I installed it, XAMPP show: The 'register_globals' directive is no longer available in PHP when I restart XAMPP.

I am moving the same code in Hosting24, but it works, who can help?

+5
source share
4 answers

I just got a slightly similar problem - definitely not an OP problem, but it falls under the title of the question.

PHP, . , undefined . , , , .

"undefined" /, - .

+4

, , - db.php . , .

, PHP , / . , , , , , , , .

. : . , FULL.

0

I had a similar problem, what is the problem: file permissions for files

0
source

Try using require_once('db.php')instead of include.

-1
source

All Articles