Php 现场警告

Php 现场警告,php,html,Php,Html,提交后,我在字段中出现错误。错误是警告:htmlspecialchars()要求参数1是字符串,数组在第420行的/path/中给出。下面是一段代码(420行) 演讲者 第节: htmlspecialchars需要一个字符串,但您给了它一个数组: 要访问数组中的一个值,只需执行以下操作: <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields[]" nam

提交后,我在字段中出现错误。错误是警告:htmlspecialchars()要求参数1是字符串,数组在第420行的/path/中给出。下面是一段代码(420行)


演讲者
第节:

htmlspecialchars
需要一个字符串,但您给了它一个数组:

要访问数组中的一个值,只需执行以下操作:

<td style="width:270px; height:50px"><input type="text" class="form-control" id="fields[]" name="fields[]" value="<?php echo htmlspecialchars($_POST['fields'][0]); ?>"></td>

当您给表单元素一个以方括号结尾的名称
字段[]
时,您将该值设置为数组

<input type="text" class="form-control" id="fields[]" name="fields[]" value="<?php echo htmlspecialchars($_POST['fields']); ?>">
htmlspecialchars()希望传递字符串,但您正在传递数组作为参数。此外,您还将每个字段作为数组发送,这就是为什么$\u POST['fields']是一个数组,其中包含属性名称等于'fields[]的每个字段。我不确定这段HTML代码是在发送电子邮件之后还是之前显示的,但我猜您正在尝试显示通过post发送的值

如果$\u POST['fields']是一个数字数组,且节值位于数组的第一个位置,则必须执行以下操作:

<td style="width:270px; height:50px"><input type="text" class="form-control" id="fields[]" name="fields[]" value="<?php echo htmlspecialchars($_POST['fields'][0]); ?>"></td>
更改此代码:

<tr>
            <td style="width:130px; height:50px">Section:</td>
            <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields0" name="fields[0]" value="<?php echo htmlspecialchars($_POST['fields'][0]); ?>"></td>
        </tr>
        <tr>
            <td style="width:130px; height:50px">Topic report:</td>
            <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields1" name="fields[1]" value="<?php echo htmlspecialchars($_POST['fields'][1]); ?>"></td>
        </tr>
        <tr>
            <td style="width:130px; height:50px">Required hardware:</td>
            <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields2" name="fields[2]" value="<?php echo htmlspecialchars($_POST['fields'][2]); ?>"></td>
        </tr>

第节:

如果要回显post数组中的特定字段,它会在错误中指出该函数只接受一个字符串。看起来它是一个数组而不是字符串。您的意思是调用hhtmlspecialchars($fields)而不是$u POST('fields')?“fields”是一个数组。在代码中的多个地方,可以显式定义它并将其用作数组。错误只是告诉您您正在调用的函数不能在数组上调用。你到底想干什么?
<tr>
            <td style="width:130px; height:50px">Section:</td>
            <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields0" name="fields[0]" value="<?php echo htmlspecialchars($_POST['fields'][0]); ?>"></td>
        </tr>
        <tr>
            <td style="width:130px; height:50px">Topic report:</td>
            <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields1" name="fields[1]" value="<?php echo htmlspecialchars($_POST['fields'][1]); ?>"></td>
        </tr>
        <tr>
            <td style="width:130px; height:50px">Required hardware:</td>
            <td style="width:270px; height:50px"><input type="text" class="form-control" id="fields2" name="fields[2]" value="<?php echo htmlspecialchars($_POST['fields'][2]); ?>"></td>
        </tr>