-2

I'm using zymichost.com trying to follow the book in the title.

This is the error I get:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user '831445_juzer'@'192.168.1.1' (using password: YES) in /www/zymichost.com/6/5/4/654456/htdocs/phpMM/connect.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at /www/zymichost.com/6/5/4/654456/htdocs/phpMM/connect.php:5) in /www/zymichost.com/6/5/4/654456/htdocs/phpMM/scripts/app_config.php on line 25

This is the app_config.php file:

<?php

// Set up debug mode
define("DEBUG_MODE", true);

// Site root
define("SITE_ROOT", "/phpMM/");

// Database connection constants

define ("DATABASE_HOST", "xxxxx");
define ("DATABASE_USERNAME", "xxxxx");
define ("DATABASE_PASSWORD", "xxxxxx");
define ("DATABASE_NAME", "xxxxxx");

// function debug print

function debug_print($message) {
   if (DEBUG_MODE) {
      echo $message;
   }
}

function handle_error($user_error_message, $system_error_message) {
   header("Location: show_error.php?" . "error_message={$user_error_message}&" . "system_error_message={$system_error_message}");
   exit();
}

?>

and this is the connect.php code:

<?php 

require_once 'scripts/app_config.php';

if (!mysql_connect(DATABASE_HOST, DATABASE_USERNAME, "foo")) { handle_error("There was a problem connecting to the database " . "that holds the information we need to get you connected.", mysql_error());
}

echo "<p>Connected to MySQL!</p>";

if (!mysql_select_db(DATABASE_NAME)) {
handle_error("There's a configuration problem with our database.", mysql_error());
}

echo "<p>Connected to MySQL, using database " . DATABASE_NAME . ".</p>";

$result = mysql_query("SHOW TABLES;");

if (!$result) {

handle_error("There's a problem looking up information in our database.", "Error in listing tables: " . mysql_error());

}

echo "<p>Tables in database:</p>";
echo "<ul>";
while ($row = mysql_fetch_row($result)) {
echo "<li>Table: {$row[0]}</li>";
}
echo "</ul>";

?>

Initially I thought it was a whitespace issue, but I guess that's not the case.

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
  • 2
    Your database username and / or password is wrong. – WWW Mar 04 '13 at 14:37
  • I've edited your question to remove the connection details, it hasn't been approved so people can still see it. Please edit your question and remove the host and password at least. It's a good thing that the issue you have is incorrect details! You realise this is on the internet and you just gave people you connection details! – piddl0r Mar 04 '13 at 14:37
  • if that's the code literally out of the book, then you need to subsitute the author's userid/password/host with your own. And you should probably throw away the book and get something more recent. The mysql functions are deprecated and should not be used anymore. – Marc B Mar 04 '13 at 14:40
  • Warning: The book you're following is **out of date**. The `mysql_xxx()` functions are not recommended for use; haven't been considered good practice for a number of years, and have recently been formally deprecated. They have been superseded by the `mysqli` and `PDO` libraries. – SDC Mar 04 '13 at 14:40
  • When you get a message that 'access is denied' it means that the grants for that user are not appropriate. You'll either need to change the grants, or contact the db administrator to do it for you. As an aside, the book you are using is out of date. mysql_* functions are deprecated and have been superceded by mysqli_* and pdo_* function sets. I'd get a newer book were I you. – dnagirl Mar 04 '13 at 14:40
  • might be worth deleting this question (once answered) if you are worried about users having seen your username/password as past revisions can easily be seen and are all kept as historical record. – Craig Taub Mar 04 '13 at 14:41
  • 1
    You cannot send `headers` after any outputs. You cannot call `header()` after any `echo` or HTML output – UnholyRanger Mar 04 '13 at 14:41
  • you can call `header()` if used for redirect. – Craig Taub Mar 04 '13 at 14:43
  • @CraigTaub Just because you can doesn't mean you should. – WWW Mar 04 '13 at 17:59
  • @Crontab I never said you should I just said its possible as allowed behaviour by PHP engine. – Craig Taub Mar 04 '13 at 19:27

1 Answers1

0

Access denied means that your credentials are wrong. Check which credentials are valid for your databse and input them in the app_config.php.

Martin Müller
  • 2,565
  • 21
  • 32