Solved

Access denied for user ''@'localhost' (using password: NO)?

Posted on 2009-04-09
6
723 Views
Last Modified: 2012-05-06
Hey. There is something wrong with my PHP-file, I think. On my homepage is some iframes which shows a PHP-file (RAY_item.php). On my homepage is also a login-check to see if an user is connected. RAY_item takes some "random" items from my MySQL and then displays them (for the user that is signed on, so that user will further down the road be able to change each item that is shown to him). The signing-on part works perfectly. But there is a problem, I think it is RAY_item that is at fault. When I enter the homepage, instead of 3-4 items in my iframe, my iframe says this:
"Access denied for user 'distende'@'localhost' (using password: NO)"

Why is that? I am certain I have typed my password and database name correctly on this. Maybe it have something to do with this: "$db = @mysql_select_db($db_name,$connection)or die(mysql_error());"
I am not sure if I should write anything and if I should, what I should write, at $db_name and $connection.

Thanks for the time!
0
Comment
Question by:MisterHamper
  • 4
6 Comments
 

Author Comment

by:MisterHamper
ID: 24108942
Or maybe it could be my index.php that contains the login-code? When you enter my site, it will check to see if you have signed on, and if you haven't, you will be redirected to another page.

Here is the top of my index.php, that contains the redirect-part

<?php
 

//prevents caching

header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");

header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");

header("Cache-Control: post-check=0, pre-check=0",false);

session_cache_limiter();

session_start();
 

require('/home6/distende/public_html/autodiet/config.php');
 

require('/home6/distende/public_html/autodiet/functions.php');
 

//this is group name or username of the group or person that you wish to allow access to

// - please be advise that the Administrators Groups has access to all pages.

if (allow_access(Users) != "yes")

{

include ('/home6/distende/public_html/autodiet/no_access.html');

exit;

}

?>
 

<html>

<head>
 

<title>

Open in new window

0
 

Author Comment

by:MisterHamper
ID: 24108950
Oh sorry, almost forgot, here is the RAY_item.php I was talking about before! :-) Hope someone can help me
<?php 
 

session_start();

 

//include config file

include ('config.php');

 

//make the connection to the database

$connection = @mysql_connect($distende_automateddiet, $distende_automat, $my password here) or die(mysql_error());

$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
 

// RAY_item.php

function RAY_item() {

/*

* Not really deleting an item, but adding it to the table of ignored items

*/

if (isset($_GET['delete']) && is_numeric($_GET['delete']))

{

        //Check if this item is already ignored (in case the user refreshed, or visited this link from the history or bookmark or something)

        if (mysql_num_rows(mysql_query("SELECT id FROM ignored_items WHERE item='".mysql_real_escape_string($_GET['delete'])."' AND userid='".mysql_real_escape_string($_SESSION['userid'])."' LIMIT 1")) > 0)

        {

                mysql_query("INSERT INTO ignored_items (item, userid) VALUES (id='").mysql_real_escape_string($_GET['delete'])."', '".mysql_real_escape_string($_SESSION['userid']."'"); //Add to the ignore table

                //If you need to delete a physical file from the server or something, that can go in here as well.

                print "File has been deleted";

        }

}

 

 

 

 

 

 

error_reporting(E_ALL);

echo "<pre>";

 

// SUBMIT POST

if(!isset($_GET['weight'])){$weight = "2000";}else{$weight = $_GET['weight'];}
 

// ASSIGN MAXIMUM TOTAL quantity FOR ITEMS

$max_quantity = ($weight/2)+35;

 

// COMPUTE MINIMUM quantity FOR THREE ITEMS - SIMULATE $min_quantity = $quantity[0] + $quantity[1] + $quantity[2];

$min_quantity = ($weight/2)-35;

asort($quantity);

$kount = 3;

foreach ($quantity as $item => $number)

{

   $kount--;

   $min_quantity = $min_quantity + $number;

   if (!$kount) break;

}

 

// NEW DATA STRUCTURE

//Pull the data from the table (limited to the max_quantity)

$query = mysql_query("SELECT * FROM items WHERE NOT EXISTS (SELECT id FROM ignored_items WHERE userid='".mysql_real_escape_string($_SESSION['userid'])."' AND item=items.id) AND page='".mysql_real_escape_string($_GET['page'])."' AND  LIMIT {$max_quantity}");

 

//Loop through each row in the query, and place it in the $items[] array; also checking for unique items

$items = array();

while ($row = mysql_fetch_array($query))

{

        if (!inarray($row, $items)) //Check to see if this is a duplicate

        {$items[] = $row;} //We set the next $items[] array index to an array of the returned rows from the DB

}

 

 

// RANDOMIZE THE LARGE ARRAY

shuffle($items);

 

// SHOW THE RESULTS

foreach ($items as $row) //This returns $row, which is an array of each row pulled from the database

{

        //Each index in $row is a string of the column name

   echo "{$row['name']} <a href=\"RAY_item.php?delete={$row['id']}\">x</a><br />";

}
 

}

echo RAY_item();

?>

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24108966
>"Access denied for user 'distende'@'localhost' (using password: NO)"

indicates that the password you specified is empty on the mysql_connect() call.

please double check for that.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 250 total points
ID: 24109180
problem with your database connection settings..

password might be wrong or access to be set to the user with password
0
 

Author Comment

by:MisterHamper
ID: 24109255
Ahh yes it was wrong. My site already connected with another script, so I had to write
"//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());"
instead onf my real username and password etc. Now it's working. Thanks both of you :-)
0
 

Author Closing Comment

by:MisterHamper
ID: 31568611
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now