V Posted May 16, 2010 Share Posted May 16, 2010 This is my first attempt querying information from a database Here's my code // include function files for this application require_once('bookmark_fns.php'); $conn = db_connect(); $result = mysql_query("SELECT * FROM bookmark"); echo $result; when I test it I get Warning: mysql_query() [function.mysql-query]: Access denied for user 'myusername'@'localhost' (using password: NO) ..... Warning: mysql_query() [function.mysql-query]: A link to the server could not be established ..... The database was installed correctly and it works with other functions but I'm not sure what I'm doing wrong with the query.. Quote Link to comment https://forums.phpfreaks.com/topic/201905-help-with-simple-query/ Share on other sites More sharing options...
glennn.php Posted May 16, 2010 Share Posted May 16, 2010 the errors are telling you that the correct data for connecting to the db are not being supplied. it thinks your username is 'myusername' and the correct db data is missing. somewhere you have a file that stores the four variables necessary: db username = 'myusername'; db password = ''; db host = 'localhost'; db = 'the name of your databse'; find that and supply the correct data, and make sure it's being included in this file, like: require_once('bookmark_fns.php'); include("db file with the variables"); Quote Link to comment https://forums.phpfreaks.com/topic/201905-help-with-simple-query/#findComment-1059124 Share on other sites More sharing options...
Mchl Posted May 16, 2010 Share Posted May 16, 2010 What is db_connect() funtion? Quote Link to comment https://forums.phpfreaks.com/topic/201905-help-with-simple-query/#findComment-1059146 Share on other sites More sharing options...
V Posted May 16, 2010 Author Share Posted May 16, 2010 @glenn thanks! I'll try that @Mchl in the db connect function I have the data that connects to the database. I think that's causing the problem. I'll just try and paste the entire code maybe. Quote Link to comment https://forums.phpfreaks.com/topic/201905-help-with-simple-query/#findComment-1059152 Share on other sites More sharing options...
glennn.php Posted May 16, 2010 Share Posted May 16, 2010 email me at glenn at glennnall dot com if you don't succeed. i'll help Quote Link to comment https://forums.phpfreaks.com/topic/201905-help-with-simple-query/#findComment-1059168 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2010 Share Posted May 16, 2010 The reason your code is attempting to make a connection to the database server at the msyql_query() statement is because your actual code that is attempting to use mysql_connect() is failing and you don't have any error checking or error reporting logic in your code to get it tell you that the connection failed or why. You also might be using short open tags and your code that is attempting to use mysql_connect() is not being seen as php code. Quote Link to comment https://forums.phpfreaks.com/topic/201905-help-with-simple-query/#findComment-1059172 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.