MisterHamper
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, $connectio n)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!
"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,
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!
ASKER
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();
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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, $connectio n)or die(mysql_error());"
instead onf my real username and password etc. Now it's working. Thanks both of you :-)
"//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,
instead onf my real username and password etc. Now it's working. Thanks both of you :-)
ASKER
Thanks
ASKER
Here is the top of my index.php, that contains the redirect-part
Open in new window