[英]Preparing HTML Form Input for SQL Database using PHP
我目前正在測試一個html表單,該表單通過php將數據發送到sql數據庫。 我面臨的問題是特殊字符會破壞表格並且不更新數據庫。 我尚未測試所有特殊字符,但主要是`
和'
是罪魁禍首。 我試過mysql_escape_string,preg_replace和add_slashes沒有成功。 我想念什么?
$description = preg_replace('/[^A-Za-z0-9\ %&$=+*?()!.-]/', ' ', $_POST['description']);
$description = preg_replace("/[\n\r]/"," ",$description);
// Items Insert
foreach ($item as $index=>$value) {
$sqlItems .= "
INSERT INTO quote_items (quote_id, item, description, amount, gst)
VALUES ('$last_id', '$item[$index]', '$description[$index]', '$amount[$index]', '$gst[$index]');
";
}
提前致謝!
您可以發布數據庫通話嗎? 特別是這兩個字符看起來在數據庫調用中會沖突。
通常將'包裹在表或列名中,將'包裹在值周圍。
這兩個都會引起問題,但是沒有代碼很難說
您可以嘗試一下(有點臟),但是應該允許保存這2個字符
$sqlItems .= '
INSERT INTO `quote_items` (quote_id, item, description, amount, gst)
VALUES ("'.$last_id.'", "'.$item[$index].'", "'.$description[$index].'", "'.$amount[$index].'", "'.$gst[$index].'");
';
編輯:對不起,引號反轉了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.