dongshi1215 2016-10-29 14:47
浏览 47
已采纳

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

I receive the following warning notice when passing an array from the HTML to the PHP:

Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in (.../post2.php on line 68)

Here's where the data are captured in the input2.php file:

<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>

Here's line 68 in the post2.php code

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

I don't know why I'm receiving the warning notice. When I print the array and elements out, they appear fine. The following code:

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;

Produces the following results:

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

The value of each individual element is:
Leonard
Julia
  • 写回答

1条回答 默认 最新

  • dtjzpg5313 2016-10-29 15:06
    关注

    You are posting HTML array: name="adult_fn_list[]", not a string. Therefore you can't pass it to mysqli_real_escape_string().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度