gaugeboson Posted April 19, 2008 Share Posted April 19, 2008 I am having some trouble pulling up the database through my PHP application. These are the error messages: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'www-data'@'localhost' (using password: YES) in /var/www/header.php on line 4 Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /var/www/header.php on line 5 Warning: mysql_query() [function.mysql-query]: Access denied for user 'www-data'@'localhost' (using password: NO) in /var/www/index.php on line 30 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/index.php on line 30 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/index.php on line 31 I don't understand what it means by using password "yes" and "no". Quote Link to comment Share on other sites More sharing options...
zenag Posted April 19, 2008 Share Posted April 19, 2008 if u have username & password to access ur database ...then check for mysql_connect("localhost","username","password") if no user & password... then.,.mysql_connect("localhost","root","") ..like this...u have to set... Quote Link to comment Share on other sites More sharing options...
gaugeboson Posted April 19, 2008 Author Share Posted April 19, 2008 Well I can access the database through MySQL Administrator. The server is localhost, say the username is "X" and the password is "Y". I have my config.php file set to this: <?php $dbhost = "localhost"; $dbhuser = "X"; $dbpassword = "Y"; $dbdatabase = "forum"; $config_basedir = "http://127.0.0.1"; ?> Yet still it does not work. Quote Link to comment Share on other sites More sharing options...
mwasif Posted April 19, 2008 Share Posted April 19, 2008 Can you post the exact code which youa re using to connect to mysql? Quote Link to comment Share on other sites More sharing options...
gaugeboson Posted April 19, 2008 Author Share Posted April 19, 2008 The errors displayed in the above post are on the index page. The index file: <?php require("header.php"); $sql = "SELECT entries.*, categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo "<h2><a href='viewentry.php?id=" . $row['id'] . "'>" . $row['subject'] . "</a></h2><br />"; echo "<i>In <a href='viewcat.php?id=" . $row['cat_id'] ."'>" . $row['cat'] . "</a> - Posted on " . date("D jS F Y g.iA", strtotime($row['dateposted'])) . "</i>"; if(isset($_SESSION['USERNAME']) == TRUE) { echo " [<a href='updateentry.php?id=" . $row['id'] . "'>edit</a>]"; } echo nl2br($row['body']); echo "</p>"; echo "<p>"; $commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] . " ORDER BY dateposted;"; $commresult = mysql_query($commsql); $numrows_comm = mysql_num_rows($commresult); if($numrows_comm == 0) { echo "<p>No Comments.</p>"; } else { echo "(<strong>" . $numrows_comm . "</strong>) comments : "; $i = 1; while($commrow = mysql_fetch_assoc($commresult)) { echo "<a href='viewentry.php?id=" . $row['id'] . "#comment" . $i . "'>" . $commrow['name'] . "</a> "; $i++; } } echo "</p>"; $prevsql = "SELECT entries.*, categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1, 5;"; $prevresult = mysql_query($prevsql); $numrows_prev = mysql_num_rows($prevresult); if($numrows_prev == 0) { echo "<p>No Previous entries.</p>"; } else { echo "<ul>"; while($prevrow = mysql_fetch_assoc($prevresult)) { echo "<li><a href='viewentry.php?id=" . $prevrow['id'] . "'>" . $prevrow ['subject'] . "</a></li>"; } } echo "</ul>"; require("footer.php"); ?> The header file: <?php session_start(); require("config.php"); $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); ?> <html> <head> <title><?php echo $config_blogname; ?></title> <link rel="stylesheet" href="1stylesheet.css" type="text/css" /> </head> <body> <div id="header"> <h1><?php echo $config_blogname; ?></h1> [<a href="index.php">Home</a>] [<a href="viewcat.php">categories</a>] <?php if(isset($_SESSION['USERNAME']) == TRUE) { echo "[<a href='logout.php'>Logout</a>]"; } else { echo "[<a href='login.php'>Login</a>]"; } if(isset($_SESSION['USERNAME']) == TRUE) { echo " - "; echo "[<a href='addentry.php'>add entry</a>]"; echo "[<a href='addcat.php'>add category</a>]"; } ?> </div> <div id="main"> The config.php file : <?php $dbhost = "localhost"; $dbhuser = ""; $dbpassword = ""; $dbdatabase = ""; $config_blogname = ""; $config_author = ""; $config_basedir = "http://127.0.0.1"; ?> Quote Link to comment Share on other sites More sharing options...
svivian Posted April 19, 2008 Share Posted April 19, 2008 Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'www-data'@'localhost' (using password: YES) in /var/www/header.php on line 4 [...] I don't understand what it means by using password "yes" and "no". The error means that the username/password combination you're using does not have the correct permissions for the database. Check your database setup or ask your host for information. The "using password: YES" part simply tells you whether you used a password to connect - it doesn't show the acutal password for security reasons (you don't want users of your site seeing that, do you?) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.