I am building a website that connects to a mysql database. When I include the file that holds the connection to the database I get an error message. If I write the code in each page the connection works fine and displays records held in database. Here is my code;
this code returns an error
<?php
/** read from the database and load to tables on the web parts page */
include ("includes/store.php");
$cars = mysql_query("SELECT * FROM cars");
while($row = mysql_fetch_array($cars))
{
$make = $row['make'];
echo $make. "<br>";
}
?>
<?php
include("includes/footer.php");
?>
the error message is:
Warning: include(includes/store.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\nicks\forms\cars.php on line 3
Warning: include() [function.include]: Failed opening 'includes/store.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\nicks\forms\cars.php on line 3
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\nicks\forms\cars.php on line 8
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\nicks\forms\cars.php on line 8
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\nicks\forms\cars.php on line 9:
But when i code like this it works fine and has no errors?
<?php
/** read from the database and load to tables on the web parts page */
$access = mysql_connect("localhost", "root", "woot");
if (!$access)
{
die ("failed to connect to database" . mysql_error($access));
}
$select = mysql_select_db("ngash", $access);
if(!$select)
{
die ("failed to connect to database" . mysql_error($select));
}
?>
<?php
$cars = mysql_query("SELECT * FROM cars");
while($row = mysql_fetch_array($cars))
{
$make = $row['make'];
echo $make. "<br>";
}
?>