功能问题php

时间:2011-03-16 05:44:31

标签: php function

这个功能有什么问题?

function validate_maxchars($t, $a, $alias, $required) {
    if(strlen($t) <= $a) {
        if(empty($t) && $required) {
            return  'Field ' . $alias . ' is required.';
        } else {
            return true;
        }
    } else {
        return 'Field ' . $alias . ' has a max of ' . $a . ' characters. You exceed the limit in ' . (strlen($t)-$a) . ' char(s).';
    }
}

$err = 0;

    $err= validate_maxchars($_POST['prod_name'], 22, 'Product Name', 0);
    if($err != 1) { return $err; } else { $data['name'] = htmlentities($_POST['prod_name'], ENT_QUOTES); }

显示错误:

        <?php
            if($err) {
        ?>
        <div id="error" style="margin: 11px 5px 0 5px; padding: 9px; background: #eeb3b3; color: white; font-weight: bold; font-size: 11px; border: 1px solid #fd9797;"><?php echo $err; ?></div>
        <?php
            }
        ?>

提交此表单时,我有一个空白页面。

3 个答案:

答案 0 :(得分:1)

添加:

error_reporting (-1);
ini_set('display_errors', 1);

答案 1 :(得分:0)

当没有错误时,它必须显示任何内容......

<?php
    if($err) {
    ?>
    <div id="error" style="margin: 11px 5px 0 5px; padding: 9px; background: #eeb3b3; color: white; font-weight: bold; font-size: 11px; border: 1px solid #fd9797;"><?php echo $err; ?></div>
    <?php
        }
        else
        echo $data['name'];
    ?>

答案 2 :(得分:0)

我可能错了,但尝试通过在文件开头执行此操作来强制错误报告,以显示任何可能的错误或警告。

 error_reporting (E_ALL);

 if( ! ini_get('display_errors') ) {
    ini_set('display_errors', 1);
 }