addslashes
我正在尝试使用一种表单更新多条记录,但在尝试使用该功能时遇到了问题。
表格如下所示:
<form name="form1" method="post" action="editnewscategorysubmit.php">
<table width="405">
<tr>
<td width="246"><span class="link1">News Category </span></td>
<td width="146" colspan="2"><span class="link1">Delete?</span></td>
</tr>
<tr>
<td>
<input type='text' name='title[]' value='$title' style='width:700px;'>
<input type='hidden' name='id[]' value='$id'>
</td>
<td>
<div style='padding-left:8px;'><a onclick='return confirmSubmit()' href='deletenewscategory.php?id=$id'><img src='images/delete.jpg' border='0'></a></div>
</td>
</tr>
<tr>
<td><input name="image" type="image" src="images/submit.png" alt="Submit Form" border="0" /></td>
<td colspan="2"> </td>
</tr>
</table>
</form>
处理这个的 PHP 代码如下所示:
$identity = $_REQUEST['id'];
$title = addslashes($_REQUEST['title']);
include 'connection.php';
for($i=0;$i<count($identity);$i++)
{
$query = "update newscategory set title = '$title[$i]' where id = '$identity[$i]'";
$result = mysql_query($query) or die(mysql_error());
}
echo "Success. The news categories were updated.";
include 'return.php';
返回的警告是:
警告:addslashes() 期望参数 1 是字符串,数组在第 71 行的 /home/u180175506/public_html/editnewscategorysubmit.php 中给出
我要做的是mysql_real_escape_string
在更新表格之前为每个值添加斜杠(或从我正在阅读的内容中,使用是首选!)。有什么我想念的吗?谢谢!