Log in

View Full Version : Problem with MySQL and PHP for blog script



lord_havoc
03-25-2007, 09:34 PM
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

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

mburt
03-25-2007, 10:09 PM
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.

lord_havoc
03-25-2007, 10:20 PM
Hmm, its still not working.

mburt
03-25-2007, 10:25 PM
The reason I told you to remove your password is because people can take them and log into your database.

lord_havoc
03-25-2007, 10:34 PM
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?

thetestingsite
03-25-2007, 10:41 PM
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.

lord_havoc
03-25-2007, 11:15 PM
Okay, I have fixed it to where the three errors inside index.php remain. i was using the wrong host and user name.

lord_havoc
03-25-2007, 11:35 PM
Now, it is all fixed. Except it does not find any content in the table news. when in fact, I have two entries.