Solved

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

Posted on 2009-04-09
6
722 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
Comment Utility
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
Comment Utility
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
Comment Utility
>"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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 79
creating 2 user ID's 5 24
php variable basic question 12 27
mysql left join sentence 7 19
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

11 Experts available now in Live!

Get 1:1 Help Now