2010-10-02 44 views
1
$ikona = "layout/achiv/a_icon.png"; 
//$opis = string of text without quotation marks 

$addit = '<img src="'.$ikona.'" onclick="alert(/'On day '.date("Y-m-d H:i:s").' user has '.htmlspecialchars($opis).'/'); ">'; 

mysql_query("UPDATE `accounts` SET `this_damn_cell`='".$addit."' 
WHERE id='".$_POST["id"]."' ") or die(mysql_error()); //error is not showing up 

echo $addit; //shows correctly 

它似乎工作正常,但在SQL基礎上沒有增加任何東西。所有字段都存在。 this_damn_cell類型是TEXT 如需任何幫助,請提前致謝:)不工作在php中的mysql_query(引號probs)

回答

2

您的代碼一直在讀取MySQL注入。

對於快速修復與mysql_escape_string請改變你的代碼如下:

$sql = sprintf('UPDATE accounts 
       SET this_damn_cell = %s 
       WHERE id='%i", mysql_escape_string($addit), mysql_escape_string($_POST['id']); 

mysql_query($sql) or die(mysql_error()); //error is not showing up 

但做準備的語句讀一位。使用PDO或MySQLi。

Taken from PHP site這是一個使用MySQL綁定的簡單示例(它可以防止MySQL注入以及您遇到的錯誤類型)。

$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); 
$stmt->bind_param('sssd', $code, $language, $official, $percent); 
+0

我需要添加一些改進,但它工作正常。謝謝! :) – Sebastian 2010-10-02 15:29:49