doqpm82240 2014-12-15 09:15
浏览 49

将错误添加到pdo_error.ctp

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 !

  • 写回答

1条回答 默认 最新

  • dongtanghuan1885 2015-02-20 04:44
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行