Results 1 to 8 of 8

Thread: Problem with MySQL and PHP for blog script

  1. #1
    Join Date
    Mar 2007
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with MySQL and PHP for blog script

    Okay, I had the help of someone write this code for me. Now I am having trouble with it. I have no experience whatsoever with PHP at all. So anything you can tell me would be be greatly appreciated

    It gives me these errors on the page the script is at.

    Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /home/cyanidep/public_html/blog/config.php on line 52

    Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'cyanidep'@'localhost' (using password: NO) in /home/cyanidep/public_html/blog/config.php on line 53

    Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/cyanidep/public_html/blog/config.php on line 53

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'cyanidep'@'localhost' (using password: NO) in /home/cyanidep/public_html/index.php on line 10

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/cyanidep/public_html/index.php on line 10

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/cyanidep/public_html/index.php on line 12


    The following is config.php
    PHP Code:
    <?php

    #### DB Connection Settings ####
    $DBserver "www.hostmonster.com"//server the mysql database is on
    $DBuser "xxxxx"//username for MySQL database
    $DBpass "xxxxx"//password for above mentioned user
    $DB "xxxxxx"//db for news


    #### DB Table Settings ####
    $newsTable "news"//table in db the news is in
    $commentsTable "comments"//table in db the comments are in

    #### HTML Template Settings ####
    /* header section up until the main content */

    $head = <<<HERE
    <html>
    <head>

    <script language="JavaScript" type="text/javascript" src="wysiwyg.js"></script>

    <script type="text/javascript">

    function confDel() {
      if (confirm("By deleting this post, you also delete all comments for it. Are you sure you wish to continue?")) {
          return true;
      }
     
      else {
          return false;
      }
    }
    </script>
    <title>Web Administration</title>

    <body>
    HERE;


    /* footer section of the page */
    $footer = <<<HERE
    </body>
    </html>
    HERE;

    /* What msg to disply if no results are found in the db */

    $noResults "<b>There are no results in the database. Please try again later.</b>";


    mysql_connect($DBserver$DBuser$DBpass);
    mysql_select_db($DB);

    ?>
    index.php is as follows

    PHP Code:
    <?php include("tempnav.php"?>

    <p>

    <!--PHP Generated Results-->
    <?php

    include("http://www.cyanideperfection.net/blog/config.php");

    $results mysql_query("SELECT * FROM `$newsTable` ORDER BY `id` DESC");

    if (
    mysql_num_rows($results) < 1) {
      echo 
    $noResults;
    }

    else {

      while (
    $qry mysql_fetch_array($results)) {
          echo 
    $qry['date']."<BR>".$qry['news']."<BR><BR>";

        
    $comments mysql_query("SELECT * FROM `$commentsTable` WHERE `newsID`='$qry[id]'");
      
        
    $cCount mysql_num_rows($comments);

          echo 
    '<a href="http://www.cyanideperfection.net/blog/comments.php?id='.$qry['id'].'" onclick="commentsWin(this.href); return false;">Comments ('.$cCount.')</a><br><br><br>';
      }
    }
    ?>

    </p>
    </div>
    </div>
    </body>
    </html>
    Hopefully, someone can help me with this. I really need this blog set up soon.

    Thanks.
    Last edited by lord_havoc; 03-25-2007 at 10:34 PM. Reason: passwords

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Whoa ... slow down. Firstly, you have to remove your database info (passwords, usernames) and replace with x's (or whatever). The problem is that you can't connect to your database. That's it: every other problem is caused from that.
    - Mike

  3. #3
    Join Date
    Mar 2007
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmm, its still not working.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The reason I told you to remove your password is because people can take them and log into your database.
    - Mike

  5. #5
    Join Date
    Mar 2007
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh, sorry. Like I said, I know nothing of PHP and I know only a little bit of how MySQL works, I didn't know that this was possible. But they are not visible anymore. Now what?

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You may want to talk to your host and make sure that your login info is correct. Other than that, the script is fine.

    The info you need is the sql server, your username, password, and the database itself.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Mar 2007
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Okay, I have fixed it to where the three errors inside index.php remain. i was using the wrong host and user name.

  8. #8
    Join Date
    Mar 2007
    Posts
    113
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Now, it is all fixed. Except it does not find any content in the table news. when in fact, I have two entries.

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
  •