传递数组时为什么会收到警告错误

时间:2016-10-29 14:47:47

标签: php html mysql html-select

将数组从HTML传递到PHP时,我收到以下警告通知:

  

警告:mysqli_real_escape_string()期望参数2为字符串,在第68行的(... / post2.php)中给出数组

这里是在input2.php文件中捕获数据的地方:

<td>
<select name="adult_fn_list[]" size="3" multiple="multiple">
<?php 
    $adult_sql = "SELECT first_name FROM member 
                    WHERE family_fkey = 34 
                    AND member_type = 'Adult' 
                    ORDER BY prim_key";
    $res=mysqli_query($link, $adult_sql) or die (mysqli_error($link));
    while($row=mysqli_fetch_assoc($res))
    echo"<option value=".$row['first_name'].">".$row['first_name']."</option>";
?>
</select>
</td>

这里是post2.php代码中的第68行

$adult_fn_list = mysqli_real_escape_string($link, $_POST[adult_fn_list]);

我不知道为什么我会收到警告通知。当我打印出阵列和元素时,它们看起来很好。以下代码:

print "The value of the adult_fn_list is: ";
print_r($_POST['adult_fn_list']);
print "<br /><br />The value of each individual element is: <br />";
Foreach ( $_POST['adult_fn_list'] as $SelectedFN )
    print ($SelectedFN . "<br />");
exit;

产生以下结果:

The value of the adult_fn_list is: Array ( [0] => Leonard [1] => Julia )

The value of each individual element is:
Leonard
Julia

1 个答案:

答案 0 :(得分:1)

您要发布HTML数组:name =“adult_fn_list []”,而不是字符串。因此,您无法将其传递给mysqli_real_escape_string()。