Hey guys, so here's what I'm trying to do:

I've made an HTTP script in the game Second Life, it uses an application/x-www-form-urlencoded url to send information to my Php script on my website. Here's the script:

<?php
define('DB_NAME', 'vangua01_access_list');
define('DB_USER', 'vangua01_admin2');
define('DB_PASSWORD', 'askljflnfldsakn');
define('DB_HOST', 'localhost');
$action=$_POST['action'];
if($action == 'connect')
{
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$link)
    {
        die('Connection failed: ' . mysql_error());
    }
    $db_selected = mysql_select_db(DB_NAME, $link);
    if (!$db_selected)
    {
        die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
    }
    else
    {
        echo('Connected to Database.');
    }
}
if($action == 'post')
{
    $avatarname = $_POST["avatarname"];
    echo('Loading '.$avatarname);
    $sql = "INSERT INTO vanguard_access (avatarname) VALUES ('$avatarname')";
    if (!mysql_query($sql))
    {
        die('Error: ' . mysql_error());
    }
}
if($action == 'done')
{
    echo('Closing connection..');
    mysql_close();
}
?>

It communicates perfectly, and returns "Connected to database." So then it's told "post" which means names of users are about to be sent to be added to the database. This is where the problem starts. It successfully echos the names of the users I send to it, but each time it should insert them into the database, it returns the error: "Access denied for user 'vangua01'@'localhost' (using pass: NO)

I've checked the credentials a hundred times, made new databases, new admins (database users have been assigned all rights) with new passwords etc to no avail. I have a working other database which I use for my registration and login on my website, so, since I know it works I tried swapping the database and user login and pass info in this for the working one, and it still returned the same error..

I've been trying to figure this out for weeks, if someone could help at all I'd be extremely grateful, thanks! :)

Recommended Answers

All 13 Replies

Is your database server hosted on the same server where the PHP is running? If not, then "localhost" is not the right value to use in DB connection. You need to make sure where the DB is hosting (you could use the IP address of the DB server as well).

Yeah, It is, like I said, I have enother database in the same place, configured the same way, and it works for my website registration and logins. Tried swapping the credentials for it into this script and still got the same error, even though I know it works.

Show us what your user priviledge (i.e. SHOW grants for 'vangua01'@'localhost';). Also, show us your database (i.e. show databases;).

Grants for vangua01@localhost
GRANT USAGE ON . TO 'vangua01'@'localhost' IDENTIFIED BY PASSWORD '57c63ca170dc2c10'
GRANT ALL PRIVILEGES ON vangua01\_registration.* TO 'vangua01'@'localhost'
GRANT ALL PRIVILEGES ON vangua01\_access\_list.* TO 'vangua01'@'localhost'
GRANT ALL PRIVILEGES ON vangua01\_%.* TO 'vangua01'@'localhost'

-

But when I try: show grants for 'vangua01_admin2'@'localhost';

I get: #1044 - Access denied for user 'vangua01'@'localhost' to database 'mysql'

I don't have access to view my own database users priveledges?

To view your own priviledges, use SHOW grants for CURRENT_USER;.

Hmm... The first previledge looks a bit odd... When I did mine, it said... GRANT USAGE PRIVILEGES ON *.* TO ... How did you issue the priviledge to overall for the user (i.e. command)???

It was done through the database manager of the control panel of my site on SiteGround.com.

Maybe I should try to issue priveledges from PhpMyAdmin using SQL commands?

You could try and see what happen.

I tried to just create a new user for the database and grant them permissionsusing this:

create user 'accesslist_admin'@'localhost' IDENTIFIED by 'n391fnbgfjf0';

And I got this:

1227 - Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

Yet, SHOW GRANTS for CURRENT_USER; still returns:

Grants for vangua01@localhost
GRANT USAGE ON . TO 'vangua01'@'localhost' IDENTIFIED BY PASSWORD '57c63ca170dc2c10'
GRANT ALL PRIVILEGES ON vangua01\_access\_list.* TO 'vangua01'@'localhost'
GRANT ALL PRIVILEGES ON vangua01\_registration.* TO 'vangua01'@'localhost'
GRANT ALL PRIVILEGES ON vangua01\_%.* TO 'vangua01'@'localhost'

What is going on??

Talked to support at my web host, SiteGround.com, they say that non-dedicated servers, as in, shared hosting, which is what I have currently, don't have the ability to create users from the SQL query box, and have to do it from the database control panel. But they claim that they have all the same permissions as when creating from inside the database.

Being that I have another database using the same style connect for my website registration and login, that works perfectly, I just plugged it's connection information into this script and ended up with the same error. This leads me to believe that the problem is with my Php script and not MySQL..

My $0.02

Second life calls your script with three possibilities: a) open a connection; b) insert a row and; c) close the connection

a doesn't have problems, although it does nothing meaningful. It just opens a connection to the database.

b, however, calls an instance of the script different from a and in this instance, there is no connection to the database, hence the 'vangua01'@'localhost' error (b1: according to the script, your indicated user is vangua01_admin2, not vangua01)

c is plainly does nothing at this point, and is redundant anyway because the connection automatically closes when the script ends.

Might I suggest just sending the avatarname with Post, and removing the conditions for mysql connect/close?

Once again, my $0.02

That's exactly what I was afraid of Scud, I noticed that the username the connection was denied for was different, but the script never had a problem connecting..

How would you suggest handling the connection though?

One thing you could do, as I said, is to send just the avatar names with Post, and remove the use of $action altogether, making the script one continuous function.

Thanks so much for the help! I was able to rewrite my script and it all works perefectly!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.