标签:
后台管理人员要给每件商品贴上RF卡作为唯一标识,所以要先给对应的RFID卡中写入响应的信息,我这里为了便于模拟演示只写入商品编号,价格,名称这几个字段,然后要把已经写入的商品上传后台,由后台写入数据库中的商品表(Goods)中,其中VB访问后台的代码如下:
‘把写入卡片的内容上传服务器,由服务器保存在数据库中,后期需要修改url等内容 Dim sssa As New WinHttpRequest Dim urlString As String = "http://mzwapitest.applinzi.com/" + "?" + "name=" + "‘" + GoodsName + "‘" Console.WriteLine(urlString) sssa.Open("GET", urlString, False) sssa.Send() ‘ 如果返回为字符串“OK”, 则显示写卡成功标识 If sssa.ResponseText.Length Then Label6.Text = "商品编码编码:" + GoodsNumb + ";商品名称:" + GoodsName + ";商品价格:" + GoodsPric + " 写入成功" + sssa.ResponseText Else ISO15693_WriteMultipleBlocks(hr, ht, 0, 112, eraseData, eraseData.Count - 1) End If
php后台如下:
<?php header("Content-type:text/html;charset = utf-8"); $name = $_GET[‘name‘]; //$numb = $_GET[‘numb‘]; //$price = $_GET[‘price‘]; //if ($name=="aaa") { //echo ‘mazhongwei‘; //} // 连主库 $db = mysql_connect(SAE_MYSQL_HOST_M.‘:‘.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); //$db = mysql_connect(w.rdc.sae.sina.com.cn.‘:‘.3307,ilzy5im2l1w4im2hl13miwmy3ky3l10h1y3l4wkh); // 连从库 // $db = mysql_connect(SAE_MYSQL_HOST_S.‘:‘.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); if ($db) { mysql_select_db(app_mzwapitest, $db); $ok = mysql_query(‘insert into Goods(name) values($name)‘); if($ok){ echo ‘OK‘; }else{ echo ‘insert error‘; } // ... }else { echo ‘openerror‘; } ?>
但是在操作过程中总是不能正确连接,后在php操作数据库的语句后天添加一条语句,用来接收sql操作失败的提示:
<?php header("Content-type:text/html;charset = utf-8"); $name = $_GET[‘name‘]; //$numb = $_GET[‘numb‘]; //$price = $_GET[‘price‘]; //if ($name=="aaa") { //echo ‘mazhongwei‘; //} // 连主库 $db = mysql_connect(SAE_MYSQL_HOST_M.‘:‘.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); //$db = mysql_connect(w.rdc.sae.sina.com.cn.‘:‘.3307,ilzy5im2l1w4im2hl13miwmy3ky3l10h1y3l4wkh); // 连从库 // $db = mysql_connect(SAE_MYSQL_HOST_S.‘:‘.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); if ($db) { mysql_select_db(app_mzwapitest, $db); $ok = mysql_query(‘insert into Goods(name) values("$name")‘); if($ok){ echo ‘OK‘; }else{ echo mysql_error(); echo ‘insert error‘; } // ... }else { echo ‘openerror‘; } ?>
然后看到返回的错误信息为:
Unknown column ‘$name‘ in ‘field list‘insert error
在网上查发现原因是:
于是在php语句操作mysql的语句进行如下修改
修改前:$ok = mysql_query(‘insert into Goods(name) values($name)‘);
修改后:$ok = mysql_query(‘insert into Goods(name) values("$name")‘);
然后就可以了。
RFID射频卡超市购物结算系统问题记录--写入卡片时,后台php无法操作数据库
标签:
原文地址:http://www.cnblogs.com/jiwangbujiu/p/5587490.html