[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 736
  • Last Modified:

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

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
MisterHamper
Asked:
MisterHamper
  • 4
2 Solutions
 
MisterHamperAuthor Commented:
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
 
MisterHamperAuthor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>"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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Loganathan NatarajanLAMP DeveloperCommented:
problem with your database connection settings..

password might be wrong or access to be set to the user with password
0
 
MisterHamperAuthor Commented:
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
 
MisterHamperAuthor Commented:
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now