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
Joined
24 May 2011
Posts
262
I'm not sure if this is causing it or it's just a typo when you copied the code but your host variable is missing a '$'.
 
Associate
Joined
13 Mar 2007
Posts
1,310
Location
Cambridgeshire
You're missing a $ before host, so it'll be trying to connect to the default host set in php.ini (most likely localhost if it's set at all).

You might want to set error reporting to all so that errors like this show up (I believe it generates an E_NOTICE):
PHP:
error_reporting(-1);

Edit: Beaten :(.
 
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:
Soldato
Joined
3 Jun 2005
Posts
3,119
Location
The South
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.
 
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");
 
Associate
Joined
4 May 2011
Posts
1,065
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.

Local database = database hosted on the machine running your code
Remote database = database running on any other machine that the one running your code.

Your OP shows that you are hosting your PHP code locally (Or dreamhosts running easyphp on Windows, which I rather doubt), but connecting to your dreamhost database.

visiblemans question is valid - normal practice would be to develop code and database on your local machine, then transfer both over to the host. Trying to run code on a local server while talking to a remote database can be problematic if the remote servers not set up to allow it, hense visiblemans question.
 
Soldato
Joined
3 Jun 2005
Posts
3,119
Location
The South
Thanks Linkex ;)


Vanhishikha - As you've found out, session_register is deprecated as of PHP 5.3.
However as mentioned, for security sake do use PDO or MySQLi rather than MySQL for DB access and similarly make sure you're sanitising POST/GET data (it doesn't look like it from the code you're posting).
 
Back
Top Bottom