2012-06-19 40 views
-1

我想傳遞的S值包含非英文字符串

.... 
$.post("ajax.php?module=test&action=updates&id="+id+"&field="+field+"&val="+sValue;          
... 

然後

$valUpdate = $_GET['val']; 
$sQuery = " UPDATE $sTable SET $colUpdate = '$valUpdate' WHERE id = $id"; 
    $req = $pdo->prepare($sQuery); 
    $req->execute(); 
    $req->closeCursor(); 

任何人都可以告訴我,我該如何解決這個問題?

謝謝

+3

'encodeURIComponent(sValue)' – Wrikken

+0

也許這將幫助你:http://stackoverflow.com/questions/834316/how-to-convert-large-utf-8-strings-into-ascii –

+0

你正在使用使用GET參數的'$ .post'。只需要設置POST參數。 – sp00m

回答

1

您應該使用encodeURIComponent(sValue)。

還可以考慮使用某種類型的SQL注入免費語法,如預準備語句。