// Severity: Notice Message: Use of undefined constant errors - assumed 'errors' Filename: views/register_user.php Line Number: 8
//I get an error(above) after I register but the good news is it displays validation errors().
//users.php
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$data['errors']=validation_errors();
}
//register_user.php
<?php if($errors = validation_errors()){
echo $errors; ?>
<div style="background:red;color:white;">
<?=errors?>
</div>
<? } ?>
答案 0 :(得分:2)
你犯了一个语法错误..在错误变量之前错过了$ ..
试试这个
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$data['errors']=validation_errors();
}
//register_user.php
<?php if($errors == validation_errors()){
echo $errors; ?>
<div style="background:red;color:white;">
<?=$errors?>
</div>
<? } ?>
答案 1 :(得分:2)
<?=errors?>
不正确。
尝试在前面放一个$符号让PHP知道它的变量,而不是常量:
<?=$errors?>
答案 2 :(得分:1)
将代码更改为以下
<?php
$errors = validation_errors();
if($errors){
?>
<div style="background:red;color:white;">
<?=$errors?>
</div>
<? } ?>