| | |
Warning: mysql_connect(): Access denied
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Ok, I thought I had gotten all the answers I needed and marked my thread as solved. But now I am having problems trying to put the code into use. I tried to insert the data from my form into my data base and got an error message. I obviously screwed something up.
Here is the code that I used. Could someone maybe look it over and see where I messed up?
Here is the code for the form I am going to use:
Here is the code for the insert.php. I did the time values in the same way as the date values, is that correct?
•
•
•
•
Warning: mysql_connect(): Access denied for user: 'xxxxxxxx@nsev7a.hostfor2bucks.com' (Using password: YES) in /var/www/html/food_journal_insert.php on line 36
Unable to select database
Here is the code for the form I am going to use:
<form action="food_journal_insert.php" method="post">
<table width="744" border="0" cellspacing="0" cellpadding="0" background="images/spiral_notebook_bg.jpg">
<tr>
<td> </td>
<td width="694"><p align="center" class="style1">What I ate today:</p>
</tr>
<tr>
<td width="50"> </td>
<td width="694">
<p>Date: <select name="date_month">
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="date_day">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="date_year">
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select>
</p>
<p><br />
How many Glasses of water did I drink today?
<input type="radio" name="water" value="1"> 1
<input type="radio" name="water" value="2"> 2
<input type="radio" name="water" value="3"> 3
<input type="radio" name="water" value="4"> 4
<input type="radio" name="water" value="5"> 5
<input type="radio" name="water" value="6"> 6
<input type="radio" name="water" value="7"> 7
<input type="radio" name="water" value="8"> 8+
<p><br />
Breakfast
<textarea name="breakfast"></textarea>
Calories
<input type="text" name="breakfast_calories" />
Time
<select name="breakfast_time_hr">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
:
<select name="breakfast_time_min">
<option value="1">00</option>
<option value="2">15</option>
<option value="3">30</option>
<option value="4">45</option>
</select>
<select name="breakfast_time_ampm">
<option value="am">am</option>
<option value="pm">pm</option>
</select>
<br />
<br />
Snack 1
<textarea name="snack_1"></textarea>
Calories
<input type="text" name="snack_1_calories" />
Time
<select name="snack_1_time_hr">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
:
<select name="snack_1_time_min">
<option value="1">00</option>
<option value="2">15</option>
<option value="3">30</option>
<option value="4">45</option>
</select>
<select name="snack_1_time_ampm">
<option value="am">am</option>
<option value="pm">pm</option>
</select>
</p> <p><br />
Lunch
<textarea name="lunch"></textarea>
Calories
<input type="text" name="lunch_calories" />
Time
<select name="lunch_time_hr">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
:
<select name="lunch_time_min">
<option value="1">00</option>
<option value="2">15</option>
<option value="3">30</option>
<option value="4">45</option>
</select>
<select name="lunch_time_ampm">
<option value="am">am</option>
<option value="pm">pm</option>
</select>
<br />
<br />
Snack 2
<textarea name="snack_2"></textarea>
Calories
<input type="text" name="snack_2_calories" />
Time
<select name="snack_2_time_hr">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
:
<select name="snack_2_time_min">
<option value="1">00</option>
<option value="2">15</option>
<option value="3">30</option>
<option value="4">45</option>
</select>
<select name="snack_2_time_ampm">
<option value="am">am</option>
<option value="pm">pm</option>
</select>
<br />
<br />
Dinner
<textarea name="dinner"></textarea>
Calories
<input type="text" name="dinner_calories" />
Time
<select name="dinner_time_hr">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
:
<select name="dinner_time_min">
<option value="1">00</option>
<option value="2">15</option>
<option value="3">30</option>
<option value="4">45</option>
</select>
<select name="dinner_time_ampm">
<option value="am">am</option>
<option value="pm">pm</option>
</select>
<br />
<br />
Snack 3
<textarea name="snack_3"></textarea>
Calories
<input type="text" name="snack_3_calories" />
Time
<select name="snack_3_time_hr">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
:
<select name="snack_3_time_min">
<option value="1">00</option>
<option value="2">15</option>
<option value="3">30</option>
<option value="4">45</option>
</select>
<select name="snack_3_time_ampm">
<option value="am">am</option>
<option value="pm">pm</option>
</select>
</p>
<p><br />
<br />
<input type="submit" value="Update My Journal"/>
</p></td>
</tr>
</table>
</form>
Here is the code for the insert.php. I did the time values in the same way as the date values, is that correct?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>food_journal_insert.php script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$username="username";
$password="password";
$database="your_database";
$client_username=$_POST['client_username'];
$TIMESTAMP=$_POST['date_year']."-".$_POST['date_month']."-".$_POST['date_day'];
$water=$_POST['water'];
$breakfast=$_POST['breakfast'];
$breakfast_calories=$_POST['breakfast_calories'];
$breakfast_time=$_POST['breakfast_time_hr'].":".$_POST['breakfast_time_min']." ".$_POST['breakfast_time_ampm'];
$snack_1=$_POST['snack_1'];
$snack_1_calories=$_POST['snack_1_calories'];
$snack_1_time=$_POST['snack_1_time_hr'].":".$_POST['snack_1_min']." ".$_POST['snack_1_ampm'];
$lunch=$_POST['lunch'];
$lunch_calories=$_POST['lunch_calories'];
$lunch_time=$_POST['lunch_time_hr'].":".$_POST['lunch_time_min']." ".$_POST['blunch_time_ampm'];
$snack_2=$_POST['snack_2'];
$snack_2_calories=$_POST['snack_2_calories'];
$snack_2_time=$_POST['snack_2_time_hr'].":".$_POST['snack_2_time_min']." ".$_POST['snack_2_time_ampm'];
$dinner=$_POST['dinner'];
$dinner_calories=$_POST['dinner_calories'];
$dinner_time=$_POST['dinner_time_hr'].":".$_POST['dinner_time_min']." ".$_POST['dinner_time_ampm'];
$snack_3=$_POST['snack_3'];
$snack_3_calories=$_POST['snack_3_calories'];
$snack_3_time=$_POST['snack_3_time_hr'].":".$_POST['snack_3_time_min']." ".$_POST['snack_3_time_ampm'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="INSERT INTO food_journal VALUES('','$client_username','$date_month','$date_day','$date_year',
'$water','$breakfast','$breakfast_calories','$breakfast_time','$snack_1','$snack_1_calories',
'$snack_1_time','$lunch','$lunch_calories','$lunch_time','$snack_2','$snack_2_calories',
'$snack_2_time','$dinner','$dinner_calories','$dinner_time','$snack_3','$snack_3_calories',
'$snack_3_time')";
mysql_query($query);
mysql_close();
?>
</body>
</html>
php Syntax (Toggle Plain Text)
mysql_connect(localhost,$username,$password);
php Syntax (Toggle Plain Text)
mysql_connect('localhost',$username,$password);
Ok, yeah, I missed that, but I still get the same error when I fixed that. Dumb question, how do you write the localhost? would it be 'daniweb', 'daniweb.com', or 'http://daniweb.com'. When I tried it with the 'http://' it came back with unknown MySQL server Host 'http'. When I tried it with the dot com at the end, the dot disappeared and was made into a space, and came up with the same error message.
•
•
•
•
areset to the correct things ? and is the database and food_journal created? is the query ssyntax valid?••••
$username="username";
$password="password";
$database="your_database";
$query="INSERT INTO food_journal VALUES
If so, that is the syntax that I got from a tutorial.
Are you still getting access denied? If so, try this:
Insert Syntax for MySQL:
If you were inserting the variables $email and $name into the table you would use:
Where the left side of VALUES is the actual fieldnames in the table and the right side of VALUES is the variables you want to insert.
php Syntax (Toggle Plain Text)
$dbhost = 'localhost'; $dbuser = 'jaysusername'; $dbpass = 'jayspassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname = 'befit4riding_com_-_journal'; mysql_select_db($dbname);
If you were inserting the variables $email and $name into the table you would use:
php Syntax (Toggle Plain Text)
INSERT INTO food_journal (email,name) VALUES ('$email','$name')";
Ok, I made the changes recommended and still get the following error message:
Here is the revised code, and I had changed jaysusername and jayspassword to the same username and password that I use to log into phpMySQL.
•
•
•
•
Warning: mysql_connect(): Access denied for user: 'jaysusername@nsev7a.hostfor2bucks.com' (Using password: YES) in /var/www/html/food_journal_insert.php on line 36
Unable to select database
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>food_journal_insert.php script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
$dbhost = 'localhost';
$dbuser = 'jaysusername';
$dbpass = 'jayspassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'befit4riding_com_-_journal';
mysql_select_db($dbname) or die( "Unable to select database");
$client_username=$_POST['client_username'];
$TIMESTAMP=$_POST['date_year']."-".$_POST['date_month']."-".$_POST['date_day'];
$water=$_POST['water'];
$breakfast=$_POST['breakfast'];
$breakfast_calories=$_POST['breakfast_calories'];
$breakfast_time=$_POST['breakfast_time_hr'].":".$_POST['breakfast_time_min']." ".$_POST['breakfast_time_ampm'];
$snack_1=$_POST['snack_1'];
$snack_1_calories=$_POST['snack_1_calories'];
$snack_1_time=$_POST['snack_1_time_hr'].":".$_POST['snack_1_min']." ".$_POST['snack_1_ampm'];
$lunch=$_POST['lunch'];
$lunch_calories=$_POST['lunch_calories'];
$lunch_time=$_POST['lunch_time_hr'].":".$_POST['lunch_time_min']." ".$_POST['blunch_time_ampm'];
$snack_2=$_POST['snack_2'];
$snack_2_calories=$_POST['snack_2_calories'];
$snack_2_time=$_POST['snack_2_time_hr'].":".$_POST['snack_2_time_min']." ".$_POST['snack_2_time_ampm'];
$dinner=$_POST['dinner'];
$dinner_calories=$_POST['dinner_calories'];
$dinner_time=$_POST['dinner_time_hr'].":".$_POST['dinner_time_min']." ".$_POST['dinner_time_ampm'];
$snack_3=$_POST['snack_3'];
$snack_3_calories=$_POST['snack_3_calories'];
$snack_3_time=$_POST['snack_3_time_hr'].":".$_POST['snack_3_time_min']." ".$_POST['snack_3_time_ampm'];
$query="INSERT INTO food_journal (client_username,date_month,date_day,date_year,
water,breakfast,breakfast_calories,breakfast_time,snack_1,snack_1_calories,
snack_1_time,lunch,lunch_calories,lunch_time,snack_2,snack_2_calories,
snack_2_time,dinner,dinner_calories,dinner_time,snack_3,snack_3_calories,
snack_3_time) VALUES ('','$client_username','$date_month','$date_day','$date_year',
'$water','$breakfast','$breakfast_calories','$breakfast_time','$snack_1','$snack_1_calories',
'$snack_1_time','$lunch','$lunch_calories','$lunch_time','$snack_2','$snack_2_calories',
'$snack_2_time','$dinner','$dinner_calories','$dinner_time','$snack_3','$snack_3_calories',
'$snack_3_time')";
mysql_query($query);
mysql_close();
?>
</body>
</html>
Last edited by jay64; Dec 8th, 2007 at 1:49 pm.
Sounds like somewhere in your connection, either the username or password is wrong. If the host was wrong the error would say Unknown MySQL server host. It's strange because usually the error would be :
Access denied for user: '*****@localhost' .
instead of
Access denied for user: 'xxxxxxxx@nsev7a.hostfor2bucks.com'
Access denied for user: '*****@localhost' .
instead of
Access denied for user: 'xxxxxxxx@nsev7a.hostfor2bucks.com'
Last edited by buddylee17; Dec 8th, 2007 at 3:45 pm.
•
•
•
•
Sounds like somewhere in your connection, either the username or password is wrong.
I'm starting to think that I need to contact the hosting company and see if there is any weird thing that needs to be done for their system.
![]() |
Similar Threads
- PHP problem! (PHP)
- Variable scope/declaration/assignment query (PHP)
- mysql_connect (PHP)
- php coding (PHP)
Other Threads in the PHP Forum
- Previous Thread: Configuring Date
- Next Thread: i want to integrate gallery 1.5 with my phpbb
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





