我正在尝试使用数组回显表单中的错误。我将错误存储在一个数组中,然后我print_r。但是当我省略某些字段并提交for时,我将字符串“Array”显示为错误。
下面是我正在使用的PHP代码...
<?php
if (isset($_POST['submit'])) {
$error = array();
if (empty($_POST['request'])) { $error .= "<li>Prayer Request is Empty</li>";}
if (empty($_POST['phone'])) { $error .= "<li>Please enter a valid phone Number</li>";}
if (empty($_POST['response'])){ $error .= "<li>Please choose a way to contact you.</li>";}
?>
<div class='Errors' >
<?php print_r ($error); ?>
</div>
答案 0 :(得分:4)
您对$error = array()
的期望是什么?
请尝试$error = "";
。
答案 1 :(得分:1)
尝试将。=更改为[] =
<?php
if (isset($_POST['submit'])) {
$error = array();
if (empty($_POST['request'])) { $error[] = "<li>Prayer Request is Empty</li>";}
if (empty($_POST['phone'])) { $error[] = "<li>Please enter a valid phone Number</li>";}
if (empty($_POST['response'])){ $error[] = "<li>Please choose a way to contact you.</li>";}
?>
<div class='Errors' >
<?php print_r ($error); ?>
</div>