Mango
Mango

Reputation: 175

Function problem php

Whats is the problem in this functions?

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); }

Show error:

        <?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
            }
        ?>

When a submit this form I've got a blank page.

Upvotes: 0

Views: 82

Answers (3)

powtac
powtac

Reputation: 41080

Add this:

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

Upvotes: 1

0xdeadbeef
0xdeadbeef

Reputation: 4140

I could be wrong but try forcing error reporting by doing this at the beginning of file to show any possible errors or warnings.

 error_reporting (E_ALL);

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

Upvotes: 0

sikas
sikas

Reputation: 5523

It has to show nothing when there is no error ...

<?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'];
    ?>

Upvotes: 0

Related Questions