SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?php require_once("include/session.php");?>
    HTML Code:
    <!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 Code:
    <?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')

    "
    );

    }
    ?>
    HTML Code:
    </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
    Last edited by molona; Jan 9, 2012 at 06:21. Reason: adding html tags for clarity

  2. #2
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,236
    Mentioned
    239 Post(s)
    Tagged
    1 Thread(s)
    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.

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Try adding 'or die' to these lines and see what comes up:
    PHP Code:
    $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 

  4. #4
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i added the
    or die('error selecting db: ' . mysql_error()),
    but it still came back with the same error.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    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.

  6. #6
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i have inserted it in the if, no error , but not inserting the table.

    PHP Code:
    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')

    "
    );
    }



  7. #7
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    i have also echoed it and thats fine to be sure the variables are working
    PHP Code:
    $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')

    "
    );
    }



  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Change that IF to:
    PHP Code:
    if('POST' === $_SERVER['REQUEST_METHOD']) 
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #9
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    it worked, could explain further, or why is the "if ($submit)" not responding


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •