Please help: Access denied for user 'root'@'localhost' (using password: NO)

Im new to php and mysql, and been tearing my head out over this for the past few hours…

/* This is the code I am using… for a test database I created…

[php] <?php
if($_GET) {
$gender = $_GET[‘gender’];
$connect = mysql_connect(“localhost”,“root”,"");
if ($connect){
mysql_select_db(“RandomData”,$connect);
$query = “SELECT * FROM RandomTable WHERE Gender=’” . $gender . “’”;
$results = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo $row[‘Name’] . “
” . $row[‘Surname’] . “
” . $row[‘Email’];
}
} else {
die (mysql_error());
}
}

?>

*/
[/php]
But when I call PHP… this is all I get “Access denied for user ‘root’@‘localhost’ (using password: NO)”

Is there a problem in the code? Or is it a configuration problem… I’m using MAMP on a MAC…

Someone please help…

There’s a password then. Since its probably the default config, check the config file for mysql and php.ini for that password. If you can’t find it there, open up phpmyadmin and create a new user.

Sponsor our Newsletter | Privacy Policy | Terms of Service