View Full Version : PHP/MySQL Problem

12-13-2003, 10:00 AM
Im am trying to write a PHP script that will connect to a mysql database. So far I have made two files: post.html, and connect.php. post.html is the file I have made that has a form in it. the form is supposed to "post" MySQL login information to config.php.

when i submit the login information to config.php i get this error message:

Warning: mysql_connect(): Access denied for user: 'mydatabase@localhost' (Using password: YES) in /home2/goobers/public_html/php2/config.php on line 10

here is the coding i used for config.php:


// MySQL Login Information

$db_username = $_POST['db_name']; // Database Username
$db_password = $_POST['db_password']; // User Password
$db_name = $_POST['db_name']; // Database Name
$db_host = $_POST['db_host']; // This will usually be localhost

$link = mysql_connect ("$db_host", "$db_username", "$db_password");

mysql_select_db ('$db_name')


What do I do to fix this problem?

12-13-2003, 05:38 PM
Usually means your password is wrong

12-13-2003, 10:43 PM
umm, I made sure I entered all the correct login information. I think my problem has to do with the coding. possibly it has to do with the other file i made, post.html. (though I could be wrong)

here is the coding i used for post.html:
(And incase it helps here is a link the the actual file: http://www.thegoobers.com/php2/post.html)

<form action="config.php" method="post">
<table border="0" cellspacing="0" cellpadding="10" class="form">

<td align="left">Database Username:</td>
<td><input class="input" type="text" name="db_name"></td></tr>

<td align="left">Database Password:</td>
<td><input class="input" type="password" name = "db_password"></td></tr>

<td align="left">Database Host:</td>
<td><input class="input" type="text" name="db_host" value="localhost"></td></tr>

<td align="left">Database Name:</td>
<td><input class="input" type="text" name="db_name"></td></tr>
<tr><td align="center" colspan="2"><input type="submit" value="Submit" class="button">


what is the error I made? and what file is it in?

12-13-2003, 11:48 PM
You've got:

$db_username = $_POST['db_name']; // Database Username

$db_name = $_POST['db_name']; // Database Name

Unless you named the user the same as your db, i'd say that this is you first problem.

Also; drop the intermediate variables and include the $_POST-variables directly inside the mysql-function
Also: drop the quotes around the variables inside the mysql-functions
Also: open a persistent connection with mysql_pconnect

12-14-2003, 01:26 AM
why do you suggest a persistent connection, if u dont mind me asking?

12-14-2003, 11:46 AM
Originally posted by ReadMe.txt
why do you suggest a persistent connection, if u dont mind me asking?
like the name says, pconnect opens a persistent connection that remains open after the script has executed, until the timout is reached.
If a new connection is needed in a later script, then the webserver will first look for an already open connection and wount open a new one.

So it's mainly a timesaver.

The possible downside, if you son't set the timoutparameter right(inside your mysql config file; my.cnf), is that you have a number of unused, open connection, which will only consume memory-resources.

But if you have substantial db-trafic on your site (high number of simultanious users or lots of querys inside your pages) then you best use pconnect and plug in a bit of extra memory.
If this doesn't have i significant performance gain or if this takes up more memoryresources then you like, then you can still remove the 'p' inside your connectionfile.
For hosted sites, i always use pconnect. Never had any complaint from host that i was eating up to much memory. (If they do their job properly, they'll set a low number of persistent connections and low timoutvalues indide the my.cnf)

Note : for webservers like IIS, pconncect or connect behave the same.