SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Access denied for user 'apache'@'localhost' (was "Help with MYSQLerrors")

    I am having major problems. Here is the link to the problem
    Here is the link for the testimonial.php script
    Here is the code for the database.php script
    I forgot to tell you if I take this part out of the testimonial.php script it works like its supposed to.
    PHP Code:
      <?php
      
    include ('reviewsconfig.php');
       
      
    // Display news item
      
    if (ISSET($_GET['newsid']))
      {
      
    connectnews();
      
    selectnews();
      
    $NEWSID $_GET['newsid'];
      
    $sql "SELECT * FROM newsitems WHERE ID = $NEWSID";
      
    $result = @mysql_query($sql);
      if (
    $result ==0)
      {
          die (
    '<p>Error performing query: ' .
               
    mysql_error() . '</p>');
      }
      
    $row mysql_fetch_array($result);
      
    $NEWSSTORY $row['NewsStory'];
      
    $NEWSDATE $row['NewsDate'];
      
    $NEWSTITLE $row['NewsTitle'];
      
    $NEWSDATE date('M,d Y'strtotime($row['NewsDate']));
      echo (
    '<h2>' $NEWSTITLE '</h2>');
      echo (
    '<p style="color: #666666"><i>Posted on ' $NEWSDATE '</i></p>');
      echo (
    '<p>' $NEWSSTORY '</p>');
      echo (
    '<p><a href="news.php">More news...</a></p>');
      
        }
         else
        {
      
      echo (
    '<h2>Testimonials on National Tour Services</h2>');
      
      
    // Display the ten most recent news items
      
    connectnews();
      
    selectnews();
      
      
    $result = @mysql_query('SELECT * FROM newsitems ORDER BY ID DESC LIMIT 10');
      if (
    $result ==0)
      {
          die (
    '<p>Error performing query: ' .
               
    mysql_error() . '</p>');
      }
      
      
    // Display news items in table
      
    echo ('');
      
      while (
    $row mysql_fetch_array($result))
      {
          
    $newsid $row['ID'];
          
    $newsdate $row['NewsDate'];
          
    $newstitle $row['NewsTitle'];
          
    $newsstory substr($row['NewsStory'], 0110);
          
    $newsdate date('M,d Y'strtotime($row['NewsDate']));
          echo (
    '<b><div style="text-align: left; margin-left: 5px;">' $newsdate '</div></b>
          <div id="newslink" style="text-align: left; margin-left: 18px;"><a href="news.php?newsid=' 
    $newsid '">' $newstitle '</a></div>
          <br />'
    );
          echo (
    '<div style="text-align: left; margin-left: 30px;">'$newsstory '</div>');
      }
      
      echo (
    '');
      }
      
    // Connect to the news database
      
      
    function connectnews()
      {
      
    $db = @mysql_connect('localhost''reviews''reviews');
      if (!
    $db)
          {
              die (
    '<p>Unable to connect to the ' .
               
    'database server at this time.</p>');
          }
      }
      
      
    // Select the news database
      
    function selectnews()
      {
      if (! @
    mysql_select_db('reviews') )
          {
              die (
    '<p>Unable to locate the news ' .
               
    'database at this time.</p>');
          }
      }
      
    mysql_close()
      
    ?>
    database.php
    PHP Code:
        <?php
        
    require_once 'config.php';
        
        
    $dbConn mysql_connect ($dbHost$dbUser$dbPass) or die ('MySQL connect failed. ' mysql_error());
        
    mysql_select_db($dbName) or die('Cannot select database. ' mysql_error());
        
        function &
    dbQuery($sql)
        {
            return 
    mysql_query($sql);
        }
        
        function 
    dbAffectedRows()
        {
            global 
    $dbConn;
            
            return 
    mysql_affected_rows($dbConn);
        }
        
        function &
    dbFetchArray($result$resultType MYSQL_NUM) {
            return 
    mysql_fetch_array($result$resultType);
        }
        
        function &
    dbFetchAssoc($result)
        {
            return 
    mysql_fetch_assoc($result);
        }
        
        function &
    dbFetchRow($result
        {
            return 
    mysql_fetch_row($result);
        }
        
        function 
    dbFreeResult($result)
        {
            return 
    mysql_free_result($result);
        }
        
        function 
    dbNumRows($result)
        {
            return 
    mysql_num_rows($result);
        }
        
        function 
    dbSelect($dbName)
        {
            return 
    mysql_select_db($dbName);
        }
        
        function 
    dbInsertId()
        {
            return 
    mysql_insert_id();
        }
        
    ?>
    Last edited by cmuench; Jan 6, 2006 at 21:20.

  2. #2
    SitePoint Enthusiast shn's Avatar
    Join Date
    Jan 2006
    Location
    Munich DE
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You forgot to tell us what your problems are!?

    Edit:

    Sorry 'bout that. When I was viewing the link back then, there were no errors. Maybe you were testing something at that very moment.
    Last edited by shn; Jan 7, 2006 at 02:50.
    Patrick

  3. #3
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry if you go to that link it will tell you. There are a bunch of them.

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure http://cmuench.ath.cx/store/testimonial.txt is the latest version of http://cmuench.ath.cx/store/testimonial.php as the error messages don't match with the code in some places, almost as if the .txt file isn't reflecting the latest .php file?

    The errors are self explanitory but without seeing the latest version the exact solution isn't clear.
    This is also a PHP problem rather than a MySQL one so maybe move it over to the PHP Forum?

  5. #5
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you look at my original post then the errors look like its from the database.php file which I listed in my original post. Thanks

  6. #6
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My problem is that I don't have a user called apache @ localhost. What does that mean? Also if I take out everything in the testimonial.php script between the <div id="content"></div> tags then the error messages go away.
    That page is located at here

  7. #7
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you look at my original post then the errors look like its from the database.php file which I listed in my original post. Thanks
    Right, but you also get an error, "Notice: Use of undefined constant result - assumed 'result' in /var/www/html/store/testimonial.php on line 71". No where in your code do i see result used in a manor that would cause that error.

    Anyway, "I don't have a user called apache @ localhost. What does that mean?".
    That's the default user and host it tries to use when none is given. The problem is your code is missing the database connection info somewhere along the line, i.e at this point:
    $sql = "SELECT * FROM newsitems WHERE ID = $NEWSID";
    $result = @mysql_query($sql);
    There is no valid connection so it tries to make one using the defaults.

  8. #8
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well at the top of the database.php file its supposed to include the config.php file which has all of that in it.

  9. #9
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are library/config.php and config.php two different files as testimonial.php uses:
    require_once 'library/config.php';
    yet database.php uses
    require_once 'config.php';

    And where does database.php get included/required?

  10. #10
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No the file config.php is in the library folder.

  11. #11
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this in in the file config.php
    PHP Code:
    require_once 'database.php'

  12. #12
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry i'm getting confused
    In config.php you have require_once 'database.php';
    According to the first post, database.php has require_once 'config.php';
    testimonial.php has require_once 'library/config.php';

    Unless /path/to/website/library is in the include_path then you'll need to use require_once 'library/config.php'; instead of require_once 'config.php'; (as testimonial.php does).

    Sorry if i'm missing the point entirely i'm just confused over the varying ways files are including each other.

  13. #13
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I haven't been espicially clear. I have this website thats due for a contest this coming tuesday. I have to devote my time to things that are also broken so I won't be able to spend anymore time on this. I thank you for all of your help though in trying to figure it out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •