deceevn Posted April 5, 2011 Share Posted April 5, 2011 Hi, I get this error when I load the page, but after hitting ctrl f5 to refresh.. the error goes away and the page works perfectly. I have edited out my details. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: YES) Access denied for user 'user'@'localhost' (using password: YES) I know everything is set right.. I just don't get it.. I am going crazy of this. Ive cleared my browser cache.. even tried it on my android phone and it does the same thing. Thanks, Deceevn Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/ Share on other sites More sharing options...
SamT_ Posted April 5, 2011 Share Posted April 5, 2011 Post the code that connects to the database (but be sure to remove your password prior to posting). Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197423 Share on other sites More sharing options...
gizmola Posted April 5, 2011 Share Posted April 5, 2011 We are not magicians, but that warning is crystal clear. Your mysql_connect is failing. You need to post your code if we're to have any chance of helping you. Use the php bbcode if you do. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197424 Share on other sites More sharing options...
deceevn Posted April 5, 2011 Author Share Posted April 5, 2011 Here is the code. It's just weird it works after hittin refresh.. makes no sense to me mysql_connect("localhost", "vikingde_lapalm", "pass") or die(mysql_error()); $category = mysql_real_escape_string($_GET['cat']); $products = mysql_query("SELECT id, prod_name, prod_img_thumb FROM vikingde_lapalm.products WHERE prod_cat='$category'"); $prod_num_rows = mysql_num_rows($products); if ($prod_num_rows==0) echo "Not A Valid Category!"; else { $i = 0; while($row = mysql_fetch_array($products)){ $i++; $id = $row['id']; $prod_name = $row['prod_name']; $prod_img_thumb = $row['prod_img_thumb']; $additionalClass = ($i % 3) == 0 ? " nomargin" : ""; echo "<li class='boxshadow " . $additionalClass . "'><br />"; echo "<a href='products_desc.php?id=$id'><img src='$prod_img_thumb' alt='' /></a>"; echo "<br />"; echo "<h5><a href='products_desc.php?id=$id'>$prod_name</a></h5>"; echo "</li>"; } } Also here is the link to the live page: http://vikingdevelopment.us/millenia/index.php Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197428 Share on other sites More sharing options...
gizmola Posted April 5, 2011 Share Posted April 5, 2011 I don't see any major problem with the code. Just looks like a case of there not being permissions for that user or the password not matching. Do you have a shell on the host, where you can try logging in with the mysql command line client? Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197441 Share on other sites More sharing options...
deceevn Posted April 5, 2011 Author Share Posted April 5, 2011 Not sure if I have shell access.. I gave the database user all privileges in cpanel.. my host is geekstorage and I have not had much luck finding helpful support information from them. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197445 Share on other sites More sharing options...
deceevn Posted April 5, 2011 Author Share Posted April 5, 2011 Ok.. I have putty and logged in as my root user but not sure exactly what to do. I do have some experience with the commands.. just not dealing with mysql. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197447 Share on other sites More sharing options...
SamT_ Posted April 5, 2011 Share Posted April 5, 2011 Use the command: mysql -u vikingde_lapalm -p vikingde_lapalm It will prompt you for a password, enter the MySQL password you use in the script. If you are successful, then your credentials are correct. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197448 Share on other sites More sharing options...
deceevn Posted April 5, 2011 Author Share Posted April 5, 2011 This is what i got: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5143036 Server version: 5.1.54-log MySQL Community Server (GPL) Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197452 Share on other sites More sharing options...
deceevn Posted April 5, 2011 Author Share Posted April 5, 2011 Any one else have and ideas? I'm all out. I am waiting to here from my hosting company, hopefully they will have some answers. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197470 Share on other sites More sharing options...
jcbones Posted April 5, 2011 Share Posted April 5, 2011 After you created your database user, did you go to the next step in cpanel, and add the user to the database? Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197484 Share on other sites More sharing options...
deceevn Posted April 5, 2011 Author Share Posted April 5, 2011 Yea I added it to the db.. its very strange.. I just noticed my other scripts are giving the same error so there has to be something going on with my hosting company or something has changed on the server that is breaking my code. Anyway.. thanks everyone for your help. I'll keep you updated if something new comes up. Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197489 Share on other sites More sharing options...
deceevn Posted April 6, 2011 Author Share Posted April 6, 2011 OK.. Turned out to be a caching problem with the server. They reset it and everything is working now. Not sure how to mark this as resolved. Thanks again for your help! I will be hanging around here Quote Link to comment https://forums.phpfreaks.com/topic/232802-strange-mysql_connect-problem/#findComment-1197809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.