Warning: mysql_connect(): Access denied for user '****'@'localhost' (using password: NO) |
Warning: mysql_connect(): Access denied for user '****'@'localhost' (using password: NO) |
Mavrik347 |
Feb 12 2011, 03:39 PM
Post
#1
|
Member Group: Members Posts: 31 Joined: 24-November 06 Member No.: 1,107 |
http://www.sev3rance.com/mav/web/
Hi guys, I can't fathom this at all so I was hoping someone had come across this before, when you go on the website news.php is loaded automatically by index.php as the pages default content. However, click "News" to reload news.php or click "Contacts" and then go back to "News" and the second time it loads it fails with: QUOTE Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'default_user'@'localhost' (using password: NO) in /home/default_user/public_html/mav/web/pages/news.php on line 2 Connect Fail:Access denied for user 'default_user'@'localhost' (using password: NO) The code to connect to the database is this: "default_user", "forum_user" and "forum_password" are used instead of actual login details for obvious reasons. config.php CODE $db_host = 'localhost'; $db_user = 'forum_user'; $db_pass = 'forum_password'; index.php CODE include 'config.php'; include 'pages/news.php'; news.php CODE $con = mysql_connect($db_host,$db_user,$db_pass); if (!$con) { die('Connect Fail:' . mysql_error()); } $db_select = mysql_select_db(sever_ipb3, $con); if (!$db_select) { die ("DB Select fail:" . mysql_error()); } However, if I change the code in news.php to type in the variables manually like this: news.php CODE $con = mysql_connect(localhost,forum_user,forum_password); if (!$con) { die('Connect Fail:' . mysql_error()); } $db_select = mysql_select_db(sever_ipb3, $con); if (!$db_select) { die ("DB Select fail:" . mysql_error()); } Then it works every time... So why is it not picking up config.php the second time? index includes it and as the page never refreshes index.php is always the master page, just loading different pages into a div. Any help would be so so appreciated. |
Ephraim F. Moya |
Feb 12 2011, 05:44 PM
Post
#2
|
Advanced Member Group: Members Posts: 167 Joined: 2-September 07 From: New Mexico Member No.: 3,702 |
|
Mavrik347 |
Feb 12 2011, 06:02 PM
Post
#3
|
Member Group: Members Posts: 31 Joined: 24-November 06 Member No.: 1,107 |
At the end of news.php I have this:
CODE mysql_close($con); Shouldn't that mean I never have 2 open connections? Once my file finishes loading it closes the connection. |
Ephraim F. Moya |
Feb 12 2011, 06:57 PM
Post
#4
|
Advanced Member Group: Members Posts: 167 Joined: 2-September 07 From: New Mexico Member No.: 3,702 |
At the end of news.php I have this: CODE mysql_close($con); Shouldn't that mean I never have 2 open connections? Once my file finishes loading it closes the connection. Probably not. It doesn't know when you've finished loading. You do. I need more code to better tell. In the meantime, open the connection, do your thing then close the connection. |
Mavrik347 |
Feb 12 2011, 07:44 PM
Post
#5
|
Member Group: Members Posts: 31 Joined: 24-November 06 Member No.: 1,107 |
Full news.php
CODE <?php //$con = mysql_connect(localhost,forum_user,forum_password); $con = mysql_connect($db_host,$db_user,$db_pass); if (!$con) { die("Connect Fail:" . mysql_error()); } $db_select = mysql_select_db(forum_database, $con); if (!$db_select) { die ("DB Select fail:" . mysql_error()); } //Connection Completed //Get post ID's from forum $idfind = mysql_query("SELECT tid,title,description,starter_id,topic_firstpost,posts,start_date FROM hhf_topics WHERE forum_id = 52 ORDER BY start_date DESC LIMIT 0,5"); while ($row = mysql_fetch_array($idfind)) { $topicid = "$row[topic_firstpost]"; //Finding topic ID for linking $tid = "$row[tid]"; //Topic Title & Description $tdesc = "$row[description]"; $ttitle = "$row[title]"; //Finding poster ID for linking $uid = "$row[starter_id]"; //Comment Caluclation $comments = "$row[posts]"; //Post Date 21600 $datecalc = $row[start_date]+21600; $postdate = date("H:i d-m-Y",$datecalc); //Get posts from the topic IDs $findpost = mysql_query("SELECT post,author_name FROM hhf_posts WHERE pid = '$topicid'"); $row2 = mysql_fetch_array($findpost); $postencoded = "$row2[post]"; $post = html_entity_decode($postencoded); echo "<div class='newstitle'>$ttitle <div class='newsdate'> $postdate </div></div>"; //echo "Description: $tdesc <br />"; echo "<div class='newscontenttop'></div><div class='newscontent'>"; echo "$post"; echo "</div>"; echo "<div class='newscontentbottom'>Author: <a href='http://www.sev3rance.com/forum/index.php?showuser=$uid'> $row2[author_name] </a> <div class='newscomments'>Comments: <a href='http://www.sev3rance.com/forum/index.php?showtopic=$tid'> $comments </a></div></div>"; echo "<br /><br />"; } mysql_close($con); ?> This post has been edited by Mavrik347: Feb 12 2011, 07:47 PM |
Ephraim F. Moya |
Feb 12 2011, 10:05 PM
Post
#6
|
Advanced Member Group: Members Posts: 167 Joined: 2-September 07 From: New Mexico Member No.: 3,702 |
CODE <?php //$con = mysql_connect(localhost,forum_user,forum_password); $con = mysql_connect($db_host,$db_user,$db_pass); if (!$con) { die("Connect Fail:" . mysql_error()); } $db_select = mysql_select_db(forum_database, $con); if (!$db_select) { die ("DB Select fail:" . mysql_error()); } //Connection Completed ....... mysql_close($con); ?> [/quote] This seems alright. Can you guarantee that $db_xx are what you expect for all connections? I see you don't have new_link in the connect query. I would start by checking that your db variables are what you expect them to be. |
Mavrik347 |
Feb 13 2011, 02:49 PM
Post
#7
|
Member Group: Members Posts: 31 Joined: 24-November 06 Member No.: 1,107 |
100% I even ovewrote them with copy/paste to ensure. The details in the variables are also 100% correct. I can copy/paste them over from config.php and it connects every time.
|
Ephraim F. Moya |
Feb 13 2011, 06:29 PM
Post
#8
|
Advanced Member Group: Members Posts: 167 Joined: 2-September 07 From: New Mexico Member No.: 3,702 |
100% I even ovewrote them with copy/paste to ensure. The details in the variables are also 100% correct. I can copy/paste them over from config.php and it connects every time. I don't know but it seems wrong to me to just copy/paste and watch it WORK. At that point you should change one thing at a time and see if you can make it work that way. Which one is the problem? According to several php forums, the mysql_connect() function has a problem with same named parameters. Force it to make a new link EVERY time and see if that helps. |
Mavrik347 |
Feb 16 2011, 09:28 PM
Post
#9
|
Member Group: Members Posts: 31 Joined: 24-November 06 Member No.: 1,107 |
Just had a thought, I looked through other people code and they seem to be doing a "new Config" fisrt...
What does that do and could that be the problem? I suspect it tell it to use a config file? |
Lo-Fi Version | Time is now: 25th April 2024 - 12:20 PM |