Page 1 of 1

Error message?

Posted: Tue Aug 30, 2011 9:44 am
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>

Re: Error message?

Posted: Tue Aug 30, 2011 10:52 am
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.

Re: Error message?

Posted: Tue Aug 30, 2011 9:36 pm
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

Re: Error message?

Posted: Wed Aug 31, 2011 7:38 pm
by eduardchile
Can you explain your reply please (I´m just a beginner!)