Jump to content

Connection Problem


gaugeboson

Recommended Posts

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". 

Link to comment
https://forums.phpfreaks.com/topic/101812-connection-problem/
Share on other sites

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. 

 

Link to comment
https://forums.phpfreaks.com/topic/101812-connection-problem/#findComment-521356
Share on other sites

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/101812-connection-problem/#findComment-521396
Share on other sites

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?)

Link to comment
https://forums.phpfreaks.com/topic/101812-connection-problem/#findComment-521498
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.