gbos Posted October 13, 2007 Share Posted October 13, 2007 Hi all, I use the following code to connect to a mysql database: if (isset($_POST['submit'])) { $conn = mysql_connect("localhost", $_POST['username'], $_POST['password']); if ($conn) { $db = mysql_select_db("bia") or die('Could not open BIA: ' . mysql_error()); $_SESSION['logged'] = 1; header( 'location:assocmain.php' ); } else { ?> <html> <head> .....more code here My problem is that when use it locally if works OK but when I use it on the hosting server I get the following message when a user either enters not username and password or the wrong username and password: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'www-data'@'localhost' (using password: NO) in /mnt/red/www/website/associate/login.php on line 7 The message is printed on the screen as if it were echo'ed. Can any one help? Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/ Share on other sites More sharing options...
emediastudios Posted October 13, 2007 Share Posted October 13, 2007 is your database the same name on your server? Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368476 Share on other sites More sharing options...
Coldman Posted October 13, 2007 Share Posted October 13, 2007 $db = mysql_select_db("bia") try this way $db = mysql_select_db("bia", $conn) Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368477 Share on other sites More sharing options...
gbos Posted October 13, 2007 Author Share Posted October 13, 2007 Yes the database is the same name on both servers, the local mysql server and the one on the web server. And I should have mentioned that if the correct username and password is entered everything goes OK. No error messages. Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368523 Share on other sites More sharing options...
gbos Posted October 13, 2007 Author Share Posted October 13, 2007 Thanks for the advice coldman but: $db = mysql_select_db("bia", $conn) did not make any difference. I suspect there may be some kind of setting difference between the two servers. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368526 Share on other sites More sharing options...
MasterACE14 Posted October 13, 2007 Share Posted October 13, 2007 add this: error_reporting(E_ALL); to the top of your PHP File, and then see if it says any errors, and/or Notice's. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368553 Share on other sites More sharing options...
gbos Posted October 13, 2007 Author Share Posted October 13, 2007 Thanks for the suggestion MasterACE14, I tried adding error_reporting(E_ALL); to the top of the code and I still got the error message: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'www-data'@'localhost' (using password: NO) in /mnt/red/www/website/associate/login.php on line 8 The only difference was the line number. Is there some kind of php configuration setting like "Echo warnings = OFF"? That is what it seems like to me because this doesn't happen with the localhost database. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368751 Share on other sites More sharing options...
gbos Posted October 13, 2007 Author Share Posted October 13, 2007 I figured it out. Thanks to the assistance give via this site and particularly MasterAce. If i add error_reporting(0); The error is not reported. Which is what I want. Check out: http://www.phpfreaks.com/phpmanual/page/function.error-reporting.html for detail. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/73065-solved-mysql_connect-problem/#findComment-368761 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.