// 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>
<? } ?>
问问题
1143 次
3 回答
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>
<? } ?>
于 2012-12-31T04:50:39.380 回答
2
<?=errors?>
是不正确的。
尝试在前面放一个 $ 符号,让 PHP 知道它是一个变量,而不是常量:
<?=$errors?>
于 2012-12-31T04:51:10.193 回答
1
将代码更改为以下
<?php
$errors = validation_errors();
if($errors){
?>
<div style="background:red;color:white;">
<?=$errors?>
</div>
<? } ?>
于 2012-12-31T04:49:29.157 回答