473,382 Members | 1,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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:

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
3 2394
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
Set password for user localhost and use password while connecting to database.
Oct 23 '14 #3
Luuk
1,047 Expert 1GB
i did not know that php could read chinese?
Oct 23 '14 #4

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

Similar topics

0
by: Ike_strong | last post by:
Can anyone help me to figure out why each time I try to access my database using: c:\mysql\bin\inmysql -root -p and afterwards:(i.e. after inputting my at the password prompt) Enter...
0
by: | last post by:
I get Access Denied (System.Runtime.InteropServices.COMException) When trying to use DirectoryEntry on IIS via ASP.NET application. The same code I use is not generating this Exception while...
2
by: SKB | last post by:
Hi, I am absolutely new to this area. I am getting the following difficulty : Access denied for user 'ODBC'@'localhost' (using password: NO) when I try the mysql command from within the...
7
by: rajbala.3399 | last post by:
Hi , I want to download sql in my linux system........... # rpm -ivh MySQL-server-5.0.24a-0.glibc23.i386.rpm MySQL-cl ient-5.0.24a-0.glibc23.i386.rpm Preparing... ...
1
usafshah
by: usafshah | last post by:
Hi I'm using linux with mysql , when i type mysql in terminal it says like: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) i'm logged in as root but...
8
by: ajos | last post by:
hi frnds, im trying to convert my servlets database configuration from ms access to mysql database.however im getting some error like no driver found exception. to verify this error ive...
1
by: whitey | last post by:
hi all, is there any other reason for this message to be displayed? other than incorrect username, password, database name?
4
by: pearl15 | last post by:
Hello All I have successfully installed the following IIS ver 6 php ver 4.4.9 MYSQL ver 5.0.67 when i tested through command line i get no error and i am view the php pages on the browser...
1
by: pearl15 | last post by:
Hello All I have successfully installed the following IIS ver 6 php ver 4.4.9 MYSQL ver 5.0.67 when i tested through command line i get no error and i am view the php pages on the browser...
1
by: vasf | last post by:
when i am trying to back up the TE(Application)config file and TE database back (MySql 5.6)i got this error message C:\Program Files\Tripwire\TE\Server\bin>tetool backup --passphrase 'pass'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.