Php 如何为不同列中的每个条目分配错误
在不同调用之间执行一些Php 如何为不同列中的每个条目分配错误,php,mysql,Php,Mysql,在不同调用之间执行一些打印($error)。或者使用xdebug逐步完成代码 无论如何,我建议您使用CMS或框架来构建,不要将所有内容都混合在一个文件中。我建议使用类似于Kohana的框架,这将使您的生活更轻松。这还将使您能够确保只有指定的字段才能进入数据库,并进行清理。不想处理大规模任务(我是来自未来的本德) 为可用字段创建一组规则 } else { // The email address is not available. echo '<div class="errormsgbo
打印($error)
。或者使用xdebug逐步完成代码
无论如何,我建议您使用CMS或框架来构建,不要将所有内容都混合在一个文件中。我建议使用类似于
Kohana
的框架,这将使您的生活更轻松。这还将使您能够确保只有指定的字段才能进入数据库,并进行清理。不想处理大规模任务(我是来自未来的本德)
为可用字段创建一组规则
} else { // The email address is not available.
echo '<div class="errormsgbox" >Either the nickname is already taken, the email address is already taken, or the alternative email you supplied is already on our system</div>';
}
编写一个方法来检查规则,然后返回消息或将其返回为true
$rules = array(
'email' => array(
'valid_email',
'not_empty'
),
'nickname' => array(
'not_empty',
)
)
有没有什么特别的原因让你选择90年代的风格,将数据库访问、HTML和CSS整合到一个巨大的
.php
文件中,而不是使用一个类似的框架,或者?这类应用程序极难改进和维护。
$rules = array(
'email' => array(
'valid_email',
'not_empty'
),
'nickname' => array(
'not_empty',
)
)
foreach ($_POST as $field)
{
if (isset($rules[$field]))
{
// Check the rules
foreach ($rules[$field] as $rule)
{
$check = call_user_func(array(Valid, $rule), $field);
if ( !$check->isValid )
{
$this->errors[] = $check->message;
}
else
{
// Insert or do whatever you need to with the data
}
}
}
}