Jump to content

Recommended Posts

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..

Link to comment
https://forums.phpfreaks.com/topic/201905-help-with-simple-query/
Share on other sites

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");

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.