surreal5335 Posted February 10, 2010 Share Posted February 10, 2010 While I have sucessfully done this in the past, I cant get it to connect for this project. Here is the link to my site: http://royalvillicus.com/photo_voting/db_fns.php Here is my code I am using to connect: function db_connect() { $connection = mysql_connect('localhost', '5335', '12345678'); if (!$connection) { return false; } } if (!mysql_select_db('photovote')) { return false; } return $connection; if(db_connect()) { echo "connected to server"; } Thanks a lot for the help Quote Link to comment https://forums.phpfreaks.com/topic/191641-mysql-function-not-connecting-to-database/ Share on other sites More sharing options...
sader Posted February 10, 2010 Share Posted February 10, 2010 this should do the job function db_connect() { $connection = mysql_connect('localhost', '5335', '12345678'); if(!$connection) { return false; } else { if(!mysql_select_db('photovote')) { return false; } else { return $connection; } } } if(db_connect()) { echo "connected to server"; } The problem is that you wrote function unfinished then u wrote return statement outside function body etc etc. It looks like u don't understand completely how the functions must be writen Quote Link to comment https://forums.phpfreaks.com/topic/191641-mysql-function-not-connecting-to-database/#findComment-1010166 Share on other sites More sharing options...
surreal5335 Posted February 10, 2010 Author Share Posted February 10, 2010 Thanks for the help, I was able to get rid of the two errors but another one popped up... mind taking a look? http://royalvillicus.com/photo_voting/db_fns.php Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/191641-mysql-function-not-connecting-to-database/#findComment-1010414 Share on other sites More sharing options...
Mchl Posted February 10, 2010 Share Posted February 10, 2010 Access denied means access denied. Check your username and password, and make sure MySQL user 5335 can connect from localhost. Quote Link to comment https://forums.phpfreaks.com/topic/191641-mysql-function-not-connecting-to-database/#findComment-1010415 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.