Connecting Tech Pros Worldwide Help | Site Map

Mysql Works On One Page But No Other!

Ajm113's Avatar
Familiar Sight
 
Join Date: Jun 2007
Posts: 161
#1: Jun 25 '08
I am running the Bizzar Server and I got mysql and php working. I created a login/logout page that does the user stuff and it works 100%. But if I used mysql on some other page I get these warnings.

Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\BizzarServer\Apache2\htdocs\index.php on line 77
  2.  
  3. Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\BizzarServer\Apache2\htdocs\index.php on line 77
  4. Access denied for user 'ODBC'@'localhost' (using password: NO)
Codes

connect.php

[PHP]<?php
// Connect to server and select databse.
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '****';

$link = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = "accountdb";
mysql_select_db($dbname);

?>[/PHP]

Some Other Page Then Login

[PHP]//Top
ob_start();
session_start();

include 'connect.php';

$query = "SELECT * FROM accountTbl";
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array( $result, MYSQL_NUM ) or die(mysql_error());

$avatar = $row['avatar'];
if($avatar == ""){
$avatar = "http://img1.jurko.net/avatar_5450.jpg";
}

echo "Welcome {$row['email']}! <br>" .
"points: {$row['points']} <br>" .
"Avatar: <img src=\"$avatar \" width=\"100px\" height=\"100px\"><br><br>";

include 'closedb.php';
?>
[/PHP]

Close.php
[PHP]<?php
include 'connect.php'

mysql_close($link);
?>
[/PHP]
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#2: Jun 25 '08

re: Mysql Works On One Page But No Other!


The error you are getting would suggest you are trying to open a database connection without passing any user information.
ODBC is the default user used when no user info is passed.

Given that your "connect.php" is hard-coded with this info, it is unlikely that the problem is there.

When you call mysql_query without an open database connection, it will attempt to open one with the default user.
I would guess that is what is happening.

So, my guess is that your "connect.php" is not being included properly, or that is is not working as it should.
Did you perhaps forget to add it to the file?
Or is it perhaps being included to late, after a query is issued?
Reply