Solved

php can't connect to db - states no password being used

Posted on 2014-01-28
8
443 Views
Last Modified: 2014-01-28
I have used the code below on another webpage I created that links to another database with no problems.  I have a new page with a new database.  I am 99% sure I added the user correctly to the new database with all the correct permissions (I even selected all permissions just in case).  I deleted the user and re-added, confirming that I am typing the password correctly.

 I get an error saying I am not sending a password, but in the code below, I am sending a password.   Help!!

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'uniqueda_ed'@'localhost' (using password: NO) in /home/uniqueda/public_html/xtime/config.php on line 22



$db_host = "localhost"; 
$db_name = "dbnameHere";
$db_user = "userNameHere";
$db_word = "passwordHere";

if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))

Open in new window

0
Comment
Question by:KCTechNet
  • 3
  • 3
  • 2
8 Comments
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 250 total points
ID: 39816877
Can you try like this,

if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word") or die (mysql_error()) )
0
 

Author Comment

by:KCTechNet
ID: 39816884
no change..  here is the complete output:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'uniqueda_ed'@'localhost' (using password: NO) in /home/uniqueda/public_html/xtime/config.php on line 22

NO DB CONNECTION:
1045 Access denied for user 'uniqueda_ed'@'localhost' (using password: NO)

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/uniqueda/public_html/xtime/config.php on line 31

NO DB SELECTION:
1045 Access denied for user 'uniqueda_ed'@'localhost' (using password: NO)
NO DATA BASE uniqueda_datatracker
0
 

Author Comment

by:KCTechNet
ID: 39816901
i should mention that it worked perfectly in xampp on my pc.  the error occurred when I moved everything to my hosted site.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39816916
It clearly says, that access denied for the user created in hosting...

Make sure check whether you have privilege to connect the db for user? also check the host name is appropriate for mysql connect

ref. http://dev.mysql.com/doc/refman//5.5/en/connection-access.html
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 39816919
To give privilege for the user, try like this command,

CREATE USER uniqueda_ed@localhost IDENTIFIED BY 'passpass';
grant all privileges on *.* to uniqueda_ed@localhost with grant option;
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 39816932
You need to find out what the correct username and host are for your hosted site.  There is no reason to think that they are the same as your WAMP installation unless you made them the same.  Hosting sites often put the MySQL servers on a different machine which means that 'localhost' won't work.   You have to use the host name or IP address to access them.
0
 

Author Comment

by:KCTechNet
ID: 39816952
wow.  I had a dollar sign in the password and it didn't like that.  Removed dollar sign and all was good.  I guess I could escape the $ but thats ok, tired of looking at that page :)
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39816966
Glad you got it working, thanks for the points.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question