Error message?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eduardchile
Forum Newbie
Posts: 3
Joined: Mon Aug 29, 2011 6:31 pm

Error message?

Post by eduardchile »

What does this message mean and how can I make it work?

Could not connect: Access denied for user 'eduardli_user'@'localhost' (using password: YES)

Code:


<html>
<body>

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$serial_no = $_POST["serial_no"];
$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("eduardli_company", $con) or die(mysql_error());


mysql_query ("INSERT INTO Products (serial_no, description, price, quantity)
VALUES ('$serial_no', '$description', '$price', '$quantity')") or die(mysql_error());

$latest="select * from Products order by serial_no desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result);
{
echo $row['serial_no'] . " " . $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}

mysql_close($con);
?>

</body>
</html>
KCAstroTech
Forum Commoner
Posts: 33
Joined: Sat Aug 27, 2011 11:16 pm

Re: Error message?

Post by KCAstroTech »

Have a look here (http://php.net/manual/en/function.mysql-connect.php) for information on the mysql_connect command and syntax.
In your code where it says:

Code: Select all

$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
The message you got is saying that access was denied to the server using that username and password. Essentially what is happening is that the php server is tying to connect to your mysql server, in this case "localhost" with the username "eduardli_user" and the password of "-z.x,c" then store the connection resource into the variable $con. Then it looks at $con to see if the connection was successful and if not display the message "Could not connect:" followed by the myql error message.

To fix this, you will need to check and make sure that your mysql server is located at "localhost", that you have a user account with the name "eduardli_user" on the mysql server, and that the password you provided is correct. If any of those are incorrect change them in the mysql_connect command.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Error message?

Post by twinedev »

And also make sure the user 'eduradli_user' is set with the proper host entry to say that it can enter from localhost
eduardchile
Forum Newbie
Posts: 3
Joined: Mon Aug 29, 2011 6:31 pm

Re: Error message?

Post by eduardchile »

Can you explain your reply please (I´m just a beginner!)
Post Reply