-2

When certain pages load on my site I have a script that will add points to the users table in the points row. Here is my script

<?php

session_start();
$db = mysqli_connect("hostname", "username", "password", "database");

$username = $_SESSION['username']; 

mysqli_query($db, 'UPDATE login_users SET points_column=points_column+1 WHERE username=$username');


?>

I have already checked the host name, username and password details and everything is correct but I keep getting this error

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'a5950626_jlf'@'10.1.1.34' (using password: YES) in /home/a5950626/public_html/application/home.php on line 5

PHP Error Message

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /home/a5950626/public_html/application/home.php on line 9

Any ideas what the problem could be or how to fix it? Thanks!

4

1 回答 1

3

Well, the error message clearly says that access is denied, so either hostname/username/password/database is wrong or the user doesn't have the required permissions.

How to set up permissions, in this example all:

GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Host is where you'd be connecting from. % can be used as a wildchar. See more detailed examples at the documentation. (you can see your user + host in the error message, btw)

As a side note, you should check that connection was successful before trying to use the database link in a query.

于 2012-10-23T18:26:41.523 回答