標籤:
後台管理員要給每件商品貼上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後台如下:
<?phpheader("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操作失敗的提示:
<?phpheader("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無法操作資料庫