我试图在将它们插入数据库之前尝试转义引号/特殊字符,而不是手动执行它,因为真正处理的数组有大约100到150个值。我误用了mysql_real_escape_string()函数吗?
$names = array(
"Intro",
"James Bond",
"M&M\'s",
"Who\'s Fault?",
"Started From Here,
"Don\'t Start",
"I\'m Still"
);
$i = 1;
foreach ($names as $inner_names => $value)
{
mysql_real_escape_string($value);
mysql_query("UPDATE MixtapeSongs
SET SongName = '$value'
WHERE MixtapeID = 524 AND
TrackNumber = '$i'")
or die("Query could not be completed!");
echo "#" . $i . " - " . $value . ".....was updated to the database!";
$i++;
}
这似乎是一个简单的修复,但我遇到了麻烦。任何帮助,将不胜感激!谢谢!
答案 0 :(得分:3)
此函数返回转义字符串,而不是引用传递,因此请执行以下操作:
$value = mysql_real_escape_string($value);