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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lingzhi0412
    New Member
    • Oct 2014
    • 2

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

    Hi guys,
    I have a trouble with error"Access denied for user ''@'localhost' (using password: NO)", Could someone give me some advice. Try to add new user but it does not work. Here is my scirpts:

    Code:
    function add_product($商品编号,      
                         $商品名称,     
                         $购买日期,     
                         $失效日期,     
                         $颜色尺寸规格,
                         $条形码,      
                         $购买价格,    
                         $税,       
                         $折扣,       
                         $汇率,       
                         $购买成本¥,    
                         $实际定价¥,    
                         $剩余库存总价¥,  
                         $预计运费¥,    
                         $参考销售价¥,   
                         $原库存,      
                         $新购数量,     
                         $销售数量,     
                         $现有库存,     
                         $商品种类,  
                         $存放地点,   
                         $更新时间,     
                         $备注        
                         ) 
    {
        // add new product information into database
    // return true or error message
    
      // connect to db
      //global $conn;
      $conn = db_connect();
      
    
      // check if product is alreday added in database
      //mysql_query("SET NAMES GBK"); //来设定MYSQL连接编码,保证页面申明编码与这里设定的连接编码一致(GBK是GB2312的扩展)。如果页面是UTF-8编码的话,可以用: 
      mysql_query("SET NAMES UTF8"); //注意是UTF8而不是一般用的UTF-8。假如页面申明的编码与数据库内部编码一致可以不设定连接编码。
      $result = $conn->query("select * from cosmetics where 商品编号='".$商品编号."'");
    
     
      if (!$result) {
        throw new Exception('无法校验产品编号是否存在系统,请联系系统管理员。');
      }
    
      if ($result->num_rows>0) {
        throw new Exception('相同商品编号已经存在系统,请输入其他商品编号,再次尝试。');
      }
      
      
      //$conn = db_connect();
     // if ok, put insert the data into database
      //mysql_query("SET NAMES GBK");  
      mysql_query("SET NAMES UTF8"); 
      $result = $conn->query("insert into cosmetics 
                             (商品编号,     
                              商品名称,     
                              购买日期,     
                              失效日期,     
                              颜色尺寸规格,   
                              条形码,      
                              购买价格,     
                              税,        
                              折扣,       
                              汇率,       
                              购买成本¥,    
                              实际定价¥,    
                              剩余库存总价¥,  
                              预计运费¥,    
                              参考销售价¥,   
                              原库存,      
                              新购数量,     
                              销售数量,     
                              现有库存,     
                              商品种类,     
                              存放地点,     
                              更新时间,     
                              备注)        
      
        values
                             ('".$商品编号."', 
                              '".$商品名称."',
                              '".$购买日期."',
                              '".$失效日期."',
                              '".$颜色尺寸规格."',
                              '".$条形码."',
                              '".$购买价格."',
                              '".$税."',
                              '".$折扣."',
                              '".$汇率."',
                              '".$购买成本¥."',
                              '".$实际定价¥."',
                              '".$剩余库存总价¥."',
                              '".$预计运费¥."',
                              '".$参考销售价¥."',
                              '".$原库存."',
                              '".$新购数量."',
                              '".$销售数量."'
                              '".$现有库存."',    
                              '".$商品种类."',    
                              '".$存放地点."',                           
                              '".$更新时间."',                              
                              '".$备注."'                            
                              )"
                              );
                              
         ini_set('error_reporting', E_ALL|E_STRICT);
    	  ini_set('display_errors', 1);       
    		mysql_query($result) or die(mysql_error());              
                          
                 
                              
      if (!$result) {
        throw new Exception('添加商品失败,请检查输入信息格式正确后,再次尝试。');
      }
    
      return true;
      }
    
    ?>
    Last edited by Dormilich; Oct 23 '14, 07:56 AM. Reason: please use code tags
  • lingzhi0412
    New Member
    • Oct 2014
    • 2

    #2
    Code:
    require('header.php');
     require_once('product_fns.php');
     
    
    
      //create short variable name
      $商品编号=$_POST['商品编号'];
      $商品名称=$_POST['商品名称'];
      $购买日期=$_POST['购买日期'];
      $失效日期=$_POST['失效日期'];
      $颜色尺寸规格=$_POST['颜色尺寸规格'];
      $条形码=$_POST['条形码'];
      $购买价格=$_POST['购买价格'];
      $税=$_POST['税'];
      $折扣=$_POST['折扣'];
      $汇率=$_POST['汇率'];
      $购买成本=$_POST['购买成本'];
      $实际定价=$_POST['实际定价'];
      $剩余库存总价=$_POST['剩余库存总价'];
      $预计运费=$_POST['预计运费'];
      $参考销售价=$_POST['参考销售价'];
      $原库存=$_POST['原库存'];
      $新购数量=$_POST['新购数量'];
      $销售数量=$_POST['销售数量'];
      $现有库存=$_POST['现有库存'];
      $商品种类=$_POST['商品种类'];
      $存放地点=$_POST['存放地点'];
      $更新时间=$_POST['更新时间'];
      $备注=$_POST['备注'];
    
      // start session which may be needed later
      // start it now because it must go before headers
      session_start();
     try   {
        // check forms filled in
        if (!filled_out($_POST)) {
          throw new Exception('输入信息不完整,请返回重新尝试。');
        }
        
        // attempt to indsert product information into database
        // this function can also throw an exception    
        
        add_product($商品编号, 
                    $商品名称, 
                    $购买日期,
                    $失效日期,
                    $颜色尺寸规格,
                    $条形码,
                    $购买价格,
                    $税,
                    $折扣,
                    $汇率,
                    $购买成本,
                    $实际定价,
                    $剩余库存总价,
                    $预计运费,
                    $参考销售价,
                    $原库存,
                    $新购数量,
                    $销售数量,
                    $现有库存,
                    $商品种类,
                    $存放地点,
                    $更新时间,
                    $备注
                    );              
                 
       
       // end page
       do_html_footer();
      }
      catch (Exception $e) {
         do_html_header('错误:');
         echo $e->getMessage();
         exit;
      }
      
          // provide link to members page
        do_html_header('恭喜');
        echo '新商品添加成功。';
        do_html_product('member.php', 'Go to members page');
      
     require('footer.php');
    
    
    ?>
    Last edited by Dormilich; Oct 23 '14, 07:56 AM. Reason: please use code tags

    Comment

    • onlinetuition
      New Member
      • Oct 2014
      • 10

      #3
      Set password for user localhost and use password while connecting to database.

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        i did not know that php could read chinese?
        Last edited by Luuk; Oct 23 '14, 04:30 PM. Reason: link corrected

        Comment

        Working...