Re: include files...
fb wrote:
> Hi everyone. I have the following code stored in a file called
> "dbConnect.php".
> I include it in a number of .PHP files (at the top of the file) with the
> line -- include ('dbConnect.php');
> I also close the connection at the bottom of the file.
>
> For some reason it doesn't seem to connect. I try to SELECT items from
> the database, but it doesn't return anything. However, if I just
> cut-and-paste the contents of the file into the top of the page, it
> works fine. Am I doing something wrong?
>
>
> # dbConnect.php
> $hostname = "localhost";
> $dbuser = "root";
> $dbpassword = "myPass";
> $dbname = "cert";
>
> $con = mysql_connect("$hostname","$dbuser","$dbpassword") ;
> if (!$con){
> die('Could not connect: ' . mysql_error());
> }
> mysql_select_db("$dbname", $con);
Start with something simple in your include file such as:
<?php
echo "Include file works.";
?>
Then at least you will know your file is getting call at all.
Then you can ascertain if the code is incorrect.
When you call the file exclude the ().
include 'dbConnect.php';
Scotty
|