422,904 Members | 1,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,904 IT Pros & Developers. It's quick & easy.

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

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1. function add_product($商品编号,      
  2.                      $商品名称,     
  3.                      $购买日期,     
  4.                      $失效日期,     
  5.                      $颜色尺寸规格,
  6.                      $条形码,      
  7.                      $购买价格,    
  8.                      $税,       
  9.                      $折扣,       
  10.                      $汇率,       
  11.                      $购买成本¥,    
  12.                      $实际定价¥,    
  13.                      $剩余库存总价¥,  
  14.                      $预计运费¥,    
  15.                      $参考销售价¥,   
  16.                      $原库存,      
  17.                      $新购数量,     
  18.                      $销售数量,     
  19.                      $现有库存,     
  20.                      $商品种类,  
  21.                      $存放地点,   
  22.                      $更新时间,     
  23.                      $备注        
  24.                      ) 
  25. {
  26.     // add new product information into database
  27. // return true or error message
  28.  
  29.   // connect to db
  30.   //global $conn;
  31.   $conn = db_connect();
  32.  
  33.  
  34.   // check if product is alreday added in database
  35.   //mysql_query("SET NAMES GBK"); //来设定MYSQL连接编码,保证页面申明编码与这里设定的连接编码一致(GBK是GB2312的扩展)。如果页面是UTF-8编码的话,可以用: 
  36.   mysql_query("SET NAMES UTF8"); //注意是UTF8而不是一般用的UTF-8。假如页面申明的编码与数据库内部编码一致可以不设定连接编码。
  37.   $result = $conn->query("select * from cosmetics where 商品编号='".$商品编号."'");
  38.  
  39.  
  40.   if (!$result) {
  41.     throw new Exception('无法校验产品编号是否存在系统,请联系系统管理员。');
  42.   }
  43.  
  44.   if ($result->num_rows>0) {
  45.     throw new Exception('相同商品编号已经存在系统,请输入其他商品编号,再次尝试。');
  46.   }
  47.  
  48.  
  49.   //$conn = db_connect();
  50.  // if ok, put insert the data into database
  51.   //mysql_query("SET NAMES GBK");  
  52.   mysql_query("SET NAMES UTF8"); 
  53.   $result = $conn->query("insert into cosmetics 
  54.                          (商品编号,     
  55.                           商品名称,     
  56.                           购买日期,     
  57.                           失效日期,     
  58.                           颜色尺寸规格,   
  59.                           条形码,      
  60.                           购买价格,     
  61.                           税,        
  62.                           折扣,       
  63.                           汇率,       
  64.                           购买成本¥,    
  65.                           实际定价¥,    
  66.                           剩余库存总价¥,  
  67.                           预计运费¥,    
  68.                           参考销售价¥,   
  69.                           原库存,      
  70.                           新购数量,     
  71.                           销售数量,     
  72.                           现有库存,     
  73.                           商品种类,     
  74.                           存放地点,     
  75.                           更新时间,     
  76.                           备注)        
  77.  
  78.     values
  79.                          ('".$商品编号."', 
  80.                           '".$商品名称."',
  81.                           '".$购买日期."',
  82.                           '".$失效日期."',
  83.                           '".$颜色尺寸规格."',
  84.                           '".$条形码."',
  85.                           '".$购买价格."',
  86.                           '".$税."',
  87.                           '".$折扣."',
  88.                           '".$汇率."',
  89.                           '".$购买成本¥."',
  90.                           '".$实际定价¥."',
  91.                           '".$剩余库存总价¥."',
  92.                           '".$预计运费¥."',
  93.                           '".$参考销售价¥."',
  94.                           '".$原库存."',
  95.                           '".$新购数量."',
  96.                           '".$销售数量."'
  97.                           '".$现有库存."',    
  98.                           '".$商品种类."',    
  99.                           '".$存放地点."',                           
  100.                           '".$更新时间."',                              
  101.                           '".$备注."'                            
  102.                           )"
  103.                           );
  104.  
  105.      ini_set('error_reporting', E_ALL|E_STRICT);
  106.       ini_set('display_errors', 1);       
  107.         mysql_query($result) or die(mysql_error());              
  108.  
  109.  
  110.  
  111.   if (!$result) {
  112.     throw new Exception('添加商品失败,请检查输入信息格式正确后,再次尝试。');
  113.   }
  114.  
  115.   return true;
  116.   }
  117.  
  118. ?>
Oct 22 '14 #1
Share this Question
Share on Google+
3 Replies


P: 2
Expand|Select|Wrap|Line Numbers
  1. require('header.php');
  2.  require_once('product_fns.php');
  3.  
  4.  
  5.  
  6.   //create short variable name
  7.   $商品编号=$_POST['商品编号'];
  8.   $商品名称=$_POST['商品名称'];
  9.   $购买日期=$_POST['购买日期'];
  10.   $失效日期=$_POST['失效日期'];
  11.   $颜色尺寸规格=$_POST['颜色尺寸规格'];
  12.   $条形码=$_POST['条形码'];
  13.   $购买价格=$_POST['购买价格'];
  14.   $税=$_POST['税'];
  15.   $折扣=$_POST['折扣'];
  16.   $汇率=$_POST['汇率'];
  17.   $购买成本=$_POST['购买成本'];
  18.   $实际定价=$_POST['实际定价'];
  19.   $剩余库存总价=$_POST['剩余库存总价'];
  20.   $预计运费=$_POST['预计运费'];
  21.   $参考销售价=$_POST['参考销售价'];
  22.   $原库存=$_POST['原库存'];
  23.   $新购数量=$_POST['新购数量'];
  24.   $销售数量=$_POST['销售数量'];
  25.   $现有库存=$_POST['现有库存'];
  26.   $商品种类=$_POST['商品种类'];
  27.   $存放地点=$_POST['存放地点'];
  28.   $更新时间=$_POST['更新时间'];
  29.   $备注=$_POST['备注'];
  30.  
  31.   // start session which may be needed later
  32.   // start it now because it must go before headers
  33.   session_start();
  34.  try   {
  35.     // check forms filled in
  36.     if (!filled_out($_POST)) {
  37.       throw new Exception('输入信息不完整,请返回重新尝试。');
  38.     }
  39.  
  40.     // attempt to indsert product information into database
  41.     // this function can also throw an exception    
  42.  
  43.     add_product($商品编号, 
  44.                 $商品名称, 
  45.                 $购买日期,
  46.                 $失效日期,
  47.                 $颜色尺寸规格,
  48.                 $条形码,
  49.                 $购买价格,
  50.                 $税,
  51.                 $折扣,
  52.                 $汇率,
  53.                 $购买成本,
  54.                 $实际定价,
  55.                 $剩余库存总价,
  56.                 $预计运费,
  57.                 $参考销售价,
  58.                 $原库存,
  59.                 $新购数量,
  60.                 $销售数量,
  61.                 $现有库存,
  62.                 $商品种类,
  63.                 $存放地点,
  64.                 $更新时间,
  65.                 $备注
  66.                 );              
  67.  
  68.  
  69.    // end page
  70.    do_html_footer();
  71.   }
  72.   catch (Exception $e) {
  73.      do_html_header('错误:');
  74.      echo $e->getMessage();
  75.      exit;
  76.   }
  77.  
  78.       // provide link to members page
  79.     do_html_header('恭喜');
  80.     echo '新商品添加成功。';
  81.     do_html_product('member.php', 'Go to members page');
  82.  
  83.  require('footer.php');
  84.  
  85.  
  86. ?>
Oct 22 '14 #2

P: 10
Set password for user localhost and use password while connecting to database.
Oct 23 '14 #3

Expert 100+
P: 921
i did not know that php could read chinese?
Oct 23 '14 #4

Post your reply

Sign in to post your reply or Sign up for a free account.