Warning: mysql_query() [function.mysql-query]: Access denied for user

hello please i can connect to a database, and i can update the registration form table in this database ,
while the i cant update the pplac table in the same database , it gives this error

Warning: mysql_query() [function.mysql-query]: Access denied for user ‘xxxxx’@‘localhost’ (using password: NO) in … on line 81
and

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in … on line 81

<?php require_once("include/session.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Reacheasy - Foremost website for easy reach of things globally</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link href="reasy.css" rel="stylesheet" type="text/css"/>  
</head>
  <body>
<div id="outer">
<div id="page">
<div id="header">

<h1>Reacheasy <span style="font-size:small;"><?php echo $_SESSION['username'];?></span></h1> 
  <ul id="nav">
    <li class="current"><a href="index.php">Home</a></li>
     <li><a href="women.php">Women</a></li>
     <li><a href="men.php">Men</a></li>
     <li><a href="children.php">Children</a></li>
     <li><a href="homeandappliances.php">Home&amp;Appliances</a></li>
     <li><a href="visionandsound.php">Vision&amp;Sounds</a></li>
      <li><a href="motoring.php">Motoring</a></li>
      <li><a href="homemore.php">More</a></li>
      <li><a href="homecontact.php">Contact us</a></li>
  </ul>
</div> <!--end of navigation div -->
</div>
<div class="y-acc-contain">
<div class="page-top">
<table width="100% class="y-acc-pagehead">
<tbody>
<tr>
<td>
<h1>
"Your account"<?php echo $_SESSION['username'];?>
</h1>
</td>
</tr>
</tbody>
</table>
</div>
<div class="column-holder">
<div class="primary">
<div class="action-box rounded">
<div class="titlebar">
<h2>shopping list</h2>
</div>
<div class="listbar">
<div>
<?php
$submit = $_POST['Add'];

//form data
$Sname = strip_tags(htmlentities($_POST['Sname']));
$Pname = strip_tags(htmlentities($_POST['Pname']));
$Pidno = strip_tags(htmlentities($_POST['Pidno']));
$Psize = strip_tags(htmlentities($_POST['Psize']));
$Pcolour = strip_tags(htmlentities($_POST['Pcolour']));
$Pquantity = strip_tags(htmlentities($_POST['Pquantity']));
$Weblink = strip_tags(htmlentities($_POST['Weblink']));
$Price = strip_tags(htmlentities($_POST['Price']));

if ($submit)

{
//open database
$connect = mysql_connect("localhost","xxxxx","xxx");
mysql_select_db("reachea2_registeringmembers");//select database

}



//check for pplac
    if ($Sname&&$Pname)
{
$queryreg = mysql_query("

INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price')

");

}
?>
</div>
<form action='youraccount.php' method='Post' class='slistbar'>
    <!--<div>
    <label for='shoppinglist' class='fixedwidth'></label>
    <textarea type='text' name='shoppinglist' id='username' cols='100' rows='15'></textarea>
    </div> -->
    
    <div>
    <label for='Sname' class='fixedwidth'>Shop name</label>
    <input type='text' name='Sname' id='Sname'/>
    </div>
    <div>
    <label for='Pname' class='fixedwidth'>Product name</label>
    <input type='text' name='Pname' id='Pname'/>
    </div>
    <div>
    <label for='Pidno' class='fixedwidth'>Product id no</label>
    <input type='text' name='Pidno' id='Pidno'/>
    </div>
    <div>
    <label for='Psize' class='fixedwidth'>Product size</label>
    <input type='text' name='Psize' id='Psize'/>
    </div>
    <div>
    <label for='Pcolour' class='fixedwidth'>Product colour</label>
    <input type='text' name='Pcolour' id='Pcolour'/>
    </div>
    <div>
    <label for='Product quantity' class='fixedwidth'>Product quantity</label>
    <select name="quantity" id="Product name">
      <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        <option>8</option>
        <option>9</option>
        <option>10</option> 
</select>
    </div>
    <div>
    <label for='Weblink' class='fixedwidth'>Web link</label>
    <input type='text' name='Weblink' id='Weblink'/>
    </div>
    <div>
    <label for='Price' class='fixedwidth'>Price GBP</label>
    <input type='text' name='Price' id='Price'/>
    </div>
    <div class='buttonarea'>
            <p>
            <input type='submit' name='submit' value='Add'>
            </p>
            </div>
            </p>
    </form>
</div>
</div>
<div class="action-box rounded">
<div class="titlebar">
<h2>bookmarks</h2>
</div>
<div class="listbar">
<form action='youraccount.php' method='Post' class='blistbar'>
    <div>
    <label for='bookmarks' class='fixedwidth'></label>
    <textarea type='text' name='bookmarks' id='username' cols='100' rows='15'></textarea>
    </div>
    <div class='buttonarea'>
            <p>
            <input type='submit' name='submit' value='Save'>
            </p>
            </div>
            </p>
    </form>
</div>
</div>
<div class="action-box rounded">
<div class="titlebar">
<h2> payment & balance</h2>
</div>
<div class="listbar">
</div>
</div>
</div>
</div>



</div>
<?php include("include/footer.php");?>


please can i get guidance

When you use Mysql_Connect, try to put the names of the server, username and password in single quotes instead of doubles. While it should work with both, sometimes a mismatched double quote can create havoc. Single quotes may help in these cases. And, in my experience, for whatever (illogical) reason, I had less problems with single quotes than with double quotes.

You may want to look into the mysqli_connect. It is the improved version.

Try adding ‘or die’ to these lines and see what comes up:

$connect = mysql_connect("localhost","xxxxx","xxx") or die('error connecting: ' . mysql_error());
mysql_select_db("reachea2_registeringmembers") or die('error selecting db: ' . mysql_error()); //select database

i added the
or die('error selecting db: ’ . mysql_error()),
but it still came back with the same error.

Then I guess that IF is never executed.
You have the connection and db selection in an if, all the rest outside of it. The first time you call the script no form has been submitted, so you don’t want to execute that INSERT. Put all of it inside the IF.

i have inserted it in the if, no error , but not inserting the table.


if ($submit)

{
//open database
$connect = mysql_connect('localhost','reachea2','HYW6QwoV') or die('error connecting: ' . mysql_error());
mysql_select_db('reachea2_registeringmembers')or die('error selecting db: ' . mysql_error());//select database
//check for pplac
	if ($Sname&&$Pname)
{
$queryreg = mysql_query("

INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price')

");
}

}

i have also echoed it and thats fine to be sure the variables are working


$submit = $_POST['Add'];

//form data
$Sname = strip_tags(htmlentities($_POST['Sname']));
$Pname = strip_tags(htmlentities($_POST['Pname']));
$Pidno = strip_tags(htmlentities($_POST['Pidno']));
$Psize = strip_tags(htmlentities($_POST['Psize']));
$Pcolour = strip_tags(htmlentities($_POST['Pcolour']));
$Pquantity = $_POST['Pquantity'];
$Weblink = strip_tags(htmlentities($_POST['Weblink']));
$Price = strip_tags(htmlentities($_POST['Price']));

echo "$Sname","$Pname";

if ($submit)

{
//open database
$connect = mysql_connect('localhost','reachea2','HYW6QwoV') or die('error connecting: ' . mysql_error());
mysql_select_db('reachea2_registeringmembers')or die('error selecting db: ' . mysql_error());//select database
//check for pplac
	if ($Sname&&$Pname)
{
$queryreg = mysql_query("

INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price')

");
}

}

Change that IF to:

if('POST' === $_SERVER['REQUEST_METHOD'])

it worked, could explain further, or why is the “if ($submit)” not responding