Link to home
Start Free TrialLog in
Avatar of MisterHamper
MisterHamperFlag for Denmark

asked on

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!
Avatar of MisterHamper
MisterHamper
Flag of Denmark image

ASKER

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

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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :-)
Thanks