PHP issues.

Associate
Joined
22 Aug 2011
Posts
240
Hey guys, I'm getting problems within my login feature of my website that i'm currently in the process of creating.

Here is the problem that I am encountering at the moment:

Warning: mysql_connect(): Access denied for user 'danclarke1'@'hostnamehere; (using password: YES) in E:\Program Files (x86)\EasyPHP-12.1\www\login\checklogin.php on line 9
cannot connect

I went into my PHP code and checked to see if there were any such problems and everything looks fine on my end, but here is the code for that also:

1 <?php
2 host="mysql.hostname.com"; // host name
3 $username="user1"; // username to log in
4 $password="testing"; // password to log in
5 $db_name="dancla"; // database name you are using for the log in
6 $tbl_name="members"; // table name you are using for the log in
7
8 // connect to the server and select the database
9 mysql_connect("$host", "$username", "$password")or die("cannot connect");
10 mysql_select_db("$db_name")or die("cannot select DB");

I have removed my personal information for security reasons, but can anyone help out with the problem here? I am confused a little.

I have even been back into my mysql settings on my control panel for my server, I use dreamhost btw and the username and password are correct, I even made a new user and tested it and it allowed me to log in to the database without any issues, so I'm just lost at the moment as to why it is being this difficult.
 
Associate
OP
Joined
22 Aug 2011
Posts
240
That was a typo on my part while editing out my personal information, I do apologise, that's my bad, there actually is a $ there, so that's not the problem :( damnit.
It seems as if it's not allowing me to log into my database. :/
 
Associate
OP
Joined
22 Aug 2011
Posts
240
Does the 'user1' have access from * or localhost ?:)

I googled around and apparently, I cannot use localhost when trying to access my database from PHP as I use dreamhost, so for me to get access to my database, I would just enter mysql.danielclarke.co and then that would be it, but yep, they have access.

I ever made a user for this occasion, I gave it a random name, a random password, applied those settings and then nothing, same error.

edit:

I located this in my settings;

Allowable Hosts
From what hosts (computers) may daniel connect to these databases?
(One per line, use % as a wildcard.)
Your current computer is: **.***.***.**

So do I have to add my computers IP Address to the allowable hosts for it to allow access to my database outside of dreamhost?

edit 2:

I have no fixed that issue that I had before, but I am now getting the following error/s:

Notice: Undefined index: mypassword in E:\Program Files (x86)\EasyPHP-12.1\www\login\checklogin.php on line 15
Wrong username or passsword, please try again

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
 
Last edited:
Associate
OP
Joined
22 Aug 2011
Posts
240
Slightly confused to why you'd do this but are you developing locally and using a remote DB? :confused:
If so then most hosts firewall DB servers, so you'd need to add your IP to the DB's whitelist.

Also you want to be looking at PDO or MySQLi for dealing with MySQL DB's within PHP and not vanilla MySQL!

Edit - looks you've found and tried the whitelisting. If you've SSH access then i'd try and connect to via MySQL command line and see if there is an issue with your credentials.
Might also be worth replicating the DB locally and seeing if the same issue arises.

I'm not using a remote database, lol.
I'm using the database that I have paid for, I'm using the database that was provided for me (created by me) on my dreamhost account.

I've fixed the issue anyhow, it was the following code: (incase anyone is interested)

$_SESSION["myusername"] = $username;
$_SESSION["mypassword"] = $password;

instead of

session_register("myusername");
session_register("mypassword");
 
Back
Top Bottom