2016-06-07 186 views
1

我試圖運行PHP這個SQL查詢:PHP SQL更新查詢失敗

UPDATE 
    billing_calldata 
SET 
    status = 'c', 
    customer = '475', 
    description = 'UK Mobile VMNO C&W (fw7-C&W)', 
    customer_cost = '0.00720416666666667', 
    customer_ac = '0', 
    customer_sc = '0', 
    reseller_cost = '0', 
    reseller_ac = '0', 
    reseller_sc = '0' 

WHERE 序列= 10364723

,但它返回這個錯誤:

UPDATE 
    billing_calldata 
SET 
    status = 'c', 
    customer = '475', 
    description = 'UK Mobile VMNO CYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''UK Mobile VMNO C' at line 1 

descriptionUK Mobile VMNO C&W (fw7-C&W)

但是q uery做工精細直接phpMyAdmin

查詢是從我的vb.net應用的業務:

if($_POST["apikey"] <> '' and $_POST["apikey"] == '1nt3gr4' and $_POST["submittedSQL"] <> '') { 
    $sql = $_POST["submittedSQL"]; 
    mysql_query($sql, $conn) or die(mysql_error()); 
} 

SQL = "UPDATE billing_calldata SET " _ 
         & "status = 'c', " _ 
         & "customer = '" & customer_sequence & "', " _ 
         & "description = '" & description & "', " _ 
         & "customer_cost = '" & customer_cost & "', " _ 
         & "customer_ac = '" & customer_ac & "', " _ 
         & "customer_sc = '" & customer_sc & "', " _ 
         & "reseller_cost = '" & reseller_cost & "', " _ 
         & "reseller_ac = '" & reseller_ac & "', " _ 
         & "reseller_sc = '" & reseller_sc & "' " _ 
         & "WHERE sequence = " & sequence & " " 
        SQL = "apikey=1nt3gr4&submittedSQL=" + SQL 

然後我在POST請求的PHP頁面,其中包含以下發送此

+1

請發佈完整的PHP代碼行,並告訴我們表的結構。 – etalon11

+0

閱讀關於轉義'PHP'中的特殊字符 – sagi

回答

0

real_escape_string逃離特殊字符:

$description = $mysqli->real_escape_string($description); 

然後在UPDATE中使用$description

+0

我可以在整個查詢中使用它嗎? – charlie

+0

@charlie:不,你不能。你必須單獨退出所有的字符串值。 – Toto

+0

我做了一個更新,我不確定這是否真的有所作爲,因爲查詢技術上在PHP頁面上運行,而vb.net只是創建查詢。檢查我的問題 – charlie