My script uses the user 'www-data' (my webserver) when connecting to the MySQL Database, while I tell it not to.

include ('config.inc.php');

$connection = mysql_connect($host, $user, $password);

mysql_select_db($database, $connection);

$shorturls = mysql_query('SELECT shorturl FROM `' . $prefix . 'urls`');
$shorturl = rand(100000, 999999);
foreach(mysql_fetch_array($shorturls) as $row)
    if($row['shorturl']==$shorturl) {
        $shorturl = rand(100000, 999999);
echo $shorturl . '<br>';
echo urldecode($_GET['longurl']) . '<br>';
mysql_query('INSERT INTO `' . $prefix . 'urls` (shorturl, longurl)
VALUES (\'' . $shorturl . '\', \'' . urldecode($_GET['longurl']) . '\')');
echo mysql_error();

I am sure it can read from the the $database, $host, $user and $password variables (tested). When I open the page i get this MySQL error:

Access denied for user 'www-data'@'localhost' (using password: NO)

I recently re-installed PHP and Apache, might have to do with it. This always used to work.

And please don't tell me mysql_*() stuff is deprecated, I know.


SOLVED: Haha, forgot to Google this. Got some DB permission errors.

Edited by lukas.vandendijssel: Solved

4 Years
Discussion Span
Last Post by Larry_Singleton

Cheers... aren't you glad you figured that out? I would be very happy, if I can solve something like that. That is an achievement. Thanks for sharing, hope people in this forum will find it helpful now and at a later date.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.