-3

This is my error:

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

And this is my set.php

<?php
$sitename = "http://www.URL.COM";
$link = mysql_connect("(ip site)", "root", "password");
$db_selected = mysql_select_db('database', $link);
mysql_query("SET NAMES utf8");

function fetchinfo($rowname,$tablename,$finder,$findervalue) {
    if($finder == "1") $result = mysql_query("SELECT $rowname FROM $tablename");
    else $result = mysql_query("SELECT $rowname FROM $tablename WHERE `$finder`='$findervalue'");
    $row = mysql_fetch_assoc($result);
    return $row[$rowname];
}
?>

I search all time answer but with no success.

halfer
  • 19,824
  • 17
  • 99
  • 186
FamousPL
  • 23
  • 1
  • 1
  • 4
  • 2
    The error is pretty self-explanatory. Have you created a user 'www-date'? Do they have a password? – Jay Blanchard May 27 '16 at 20:36
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 27 '16 at 20:36
  • [Little Bobby](http://bobby-tables.com/) says [your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard May 27 '16 at 20:37
  • My guess is that it's logging in with local credentials - the code is most likely running under www-data and there is no corresponding account in the DB. – T Gray May 27 '16 at 20:44
  • Someone can change this to work i need this ;/ – FamousPL May 27 '16 at 20:45
  • @JayBlanchard no i dont have created user www-data – FamousPL May 27 '16 at 20:45
  • it's very unclear to me why it's not using `"root", "password"` credentials. But I can say that you need to actually call `fetchinfo` – Jeff Puckett May 27 '16 at 20:48
  • Can you change this for me ? please – FamousPL May 27 '16 at 20:50
  • @jayblanchard I Use PHP5 – FamousPL May 27 '16 at 20:50

1 Answers1

3

As you're not using password, why you write like this:

$link = mysql_connect("(ip site)", "root", "password");

If your username = "root" on localhost then try to write the connection like the following way:

<?php

$link = mysql_connect('localhost', 'root', '{Your Password}');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('{Your DB Name}', $link);
if (!$db_selected) {
    die ('Can\'t use {Your DB Name} : ' . mysql_error());
}

For details check: MySQL

Note: Try to use PDO or mysqli

MySQLi

PDO

Saleh Ahmad Oyon
  • 672
  • 1
  • 6
  • 20