Reputation: 57
I'm new with mysql and php so please bear with me. I'm trying to connect my first form to a table and I keep running into a new issue every time I "fix" something. I'm trying to test my form to make sure it connects before I move forward. This is the form:
<form action="demo.php" method="post">
<p>input 1: <input type="text" name="input1"/></p>
<input type="submit" value="Submit" />
</form>
and this is my "demo.php" file:
<?php
define('BD_NAME', 'DEMO');
define('DB_USER', 'DEMO');
define('DB_PASSWORD', 'PASSWORD');
define('DB_HOST', 'HOST');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
echo 'Connected successfully';
mysql_close();
?>
I keep getting this error:
Can't use DB_NAME: Access denied for user 'USER'@'%' to database 'DB_NAME'
Again I'm new at this and I'd appreciate any help. Thanks!!
Upvotes: 0
Views: 51
Reputation: 1063
always use error_reporting(E_ALL) and display errors while coding to avoid these mistakes
Upvotes: 0
Reputation: 6913
You have a typo.
define('BD_NAME', 'DEMO');
should be define('DB_NAME', 'DEMO');
Notice the DB_NAME
global variable that is not resolve :
Can't use >>>>DB_NAME<<<<: Access denied for user 'USER'@'%' to database 'DB_NAME'
It means that either DB_NAME
is not declared OR that the value of DB_NAME
is "DB_NAME".
Upvotes: 1