Trackvia忽略包含撇号的记录

时间:2014-12-10 02:23:29

标签: php

两者

'CUSTOMER' => htmlspecialchars($tmpArray['Customer_Bill_Name'], ENT_QUOTES)

 'CUSTOMER' => mysqli_real_escape_string($con, $tmpArray['Customer_Bill_Name']), 

无法解决我的问题转义'撇号

我有'CUSTOMER'字段,它是linked field(dropdown list),表示此字段中的值来自另一个表。要在此字段中添加/选择Customer_Bill_name等效项,您需要具有完全匹配的记录,这意味着CUSTOMER必须与Customer_Bill_Name的值完全相等。

但是当Customer_Bill_Name包含'撇号例如XXX'S LLC时,我遇到了问题。

我试过var_dump()print_r()看看数据是怎么样的,但我看不出问题是什么问题,当试图输入记录时它没有,我试图发送一个数组与out Customer_Bill_name工作正常。

$记录

     $records=array(
      'CUSTOMER' => mysql_escape_string($tmpArray['Customer_Bill_Name']),
      'WHEEL PN 1-S' => htmlspecialchars($wheelpn, ENT_QUOTES),
      'QUANTITY'          => htmlspecialchars($tmpArray['Quantity'], ENT_QUOTES),
      'SO DATE'          =>htmlspecialchars($tmpArray['TransactionDate'], ENT_QUOTES),
      'SO NUMBER'         => htmlspecialchars($tmpArray['Reference'], ENT_QUOTES),
       'CUSTOMER PN' => htmlspecialchars($tmpArray['PartNumber'], ENT_QUOTES),

      'SHIP VIA'         => htmlspecialchars($tmpArray['WhichShipVia'], ENT_QUOTES),
      'PROMISED DATE'         => htmlspecialchars($tmpArray['ShipByDate'], ENT_QUOTES),
      'COMMENTS'         => htmlspecialchars($tmpArray['Comment'], ENT_QUOTES),
      'PO #'         => htmlspecialchars($tmpArray['CustomerInvoiceNo'], ENT_QUOTES),   
      'WO Notes'         =>htmlspecialchars($tmpArray['SalesDescription'], ENT_QUOTES),
      'ROUTING'         =>htmlspecialchars($routing, ENT_QUOTES),


   );

$tv->addRecord($tableId, $records);

// addRecord()函数

  /**
 * Add more than one record at once to a table. Batch inserts.
 * 
 * @param  int   $tableId
 * @param  array $records
 * @return array
 */
 public function addRecords($tableId, $records)
   {
     $url = self::BASE_URL . self::RECORDS_URL;
     $data = array(
     'table_id' => $tableId,
     'records' => $records
    );
    return $this->api($url, 'POST', json_encode($data), 'json');
    }

var_dump($tableId)var_dump($records)var_dump($this->api(...))

    int(45454270957) array(12) { 
             ["CUSTOMER"]=> NULL 
             ["WHEEL PN 1-S"]=> string(0) "" 
             ["QUANTITY"]=> string(21) "2.0000000000000000000" 
             ["SO DATE"]=> string(10) "2010-12-02" 
             ["SO NUMBER"]=> string(5) "655028" 
             ["CUSTOMER PN"]=> string(0) "" 
             ["SHIP VIA"]=> string(3) "DHL" 
             ["PROMISED DATE"]=> string(10) "2014-12-23" 
             ["COMMENTS"]=> string(0) "" 
             ["PO #"]=> string(4) "98430" 
             ["WO Notes"]=> string(16) "sps990X15 8-8 JDY" 
             ["ROUTING"]=> string(0) "" } NULL 

请帮助谢谢!

1 个答案:

答案 0 :(得分:0)

问题在于mysqli_real_escape_string() returns an empty string if a MySQL connection hasn't been established。由于您使用外部API进行记录管理,我怀疑MySQL连接从未存在过。

因此,您要向Trackvia API发送错误数据 - 这会返回NULL响应。

解决方案是使用非MySQL库将数据解析/清理到API中。我建议str_replace代表您的API遇到问题的字符。

htmlspecialchars无效,因为ENT_QUOTES'等字符将成为'"将成为" 。你认为它var_dump时它可以正常工作,因为HTML实体被渲染回报价。因此,XXX's AG实际上存储为XXX's AG