1

I want to add some errors in to pdo_error.ctp. What I exactly want to do? I have a form where I can insert values in to MySQL database, if I leave text or varchar input empty then its inserting in to database, but if I leave INT input empty, then I got error. I want error message even if text/varchar input is empty.

My database structure: enter image description here

What I got if I leave INT input empty:

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Maja' cannot be null

SQL Query: INSERT INTO `kontaktid`.`kontaktids` (`Eesnimi`, `Perenimi`, `Maakond`, `Linn`, `Tanav`, `Maja`, `Telefon`, `lisanumbrid`) VALUES ('', '', '', '', '', NULL, NULL, '') 

Notice: If you want to customize this error message, create app\View\Errors\pdo_error.ctp

pdo_error.ctp file

<h2><?php echo __d('cake_dev', 'Database Error'); ?></h2>
<p class="alert alert-error">
        <button class="close" data-dismiss="alert">×</button>
        <strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
        <?php echo h($error->getMessage()); ?>
</p>
<?php if (!empty($error->queryString)) : ?>
        <p class="alert alert-info">
        <button class="close" data-dismiss="alert">×</button>
            <strong><?php echo __d('cake_dev', 'SQL Query'); ?>: </strong>
            <?php echo $error->queryString; ?>
        </p>
<?php endif; ?>
<?php if (!empty($error->params)) : ?>
                <strong><?php echo __d('cake_dev', 'SQL Query Params'); ?>: </strong>
                <?php echo Debugger::dump($error->params); ?>
<?php endif; ?>
<p class="alert alert-info">
        <button class="close" data-dismiss="alert">×</button>
        <strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
        <?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'pdo_error.ctp'); ?>
</p>
<?php echo $this->element('exception_stack_trace'); ?>

What I already tried :

I added this in to view.ctp file

$Eesnimi = ($_POST['Eesnimi']);

And then added this in to pdo_error.ctp file

if (empty($Eesnimi)) {
    echo "Eesnimi is empty";
}

I really want get error, if these text inputs are empty. I can add form file too, if its necessary.

Thanks for helping !

frantsium
  • 180
  • 3
  • 19

1 Answers1

0

Have a look at data validation: http://book.cakephp.org/2.0/en/models/data-validation.html

user3082321
  • 654
  • 5
  • 12