无效的表单数据是返回值的“ 0”。在数据库中

发布于 2025-01-30 02:20:43 字数 658 浏览 2 评论 0原文

我正在尝试将一个空输入字段存储到我的数据库中,并希望将其存储为“ null”,但是,如果我在提交表单时将输入字段留为空,则将其存储为“ 0”在我的数据库中。

在我的控制器中,我有以下内容:

$campaignRules = [
            'lines_available' => 'nullable|numeric',
        ];

以我的形式,我有:

<div class="col-xl-12 input-container">
    <label for="" class="f-14 text-grey label">
        Lines Available (optional)
    </label>
    <input name="lines_available" type="number" class="custom-form" placeholder="Enter lines available...">
</div>

在我的数据库中,我将字段存储为整数,已检查“允许nullable”检查,并且将字段集的默认值设置为“ null”。我想不出任何其他原因,为什么将其存储为0,并将其设置为所有的东西。

有指导吗?再次感谢。

I'm trying to store an empty input field into my database and would like for it to be stored as "NULL", however, If I leave the input field empty when I go to submit my form, It is stored as "0" in my database.

In my controller, I have the following:

$campaignRules = [
            'lines_available' => 'nullable|numeric',
        ];

In my form I have:

<div class="col-xl-12 input-container">
    <label for="" class="f-14 text-grey label">
        Lines Available (optional)
    </label>
    <input name="lines_available" type="number" class="custom-form" placeholder="Enter lines available...">
</div>

In my database, I have the field stored as an integer, have "Allow Nullable" checked and have the default value of the field set as "NULL". I can't think of any other reason as to why it would be stored as 0 with all the things I have set in place.

Any guidance? Thanks again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[旋木] 2025-02-06 02:20:43

我通过执行以下操作修复了它:

if ($_REQUEST['lines_available'] == 0) {
    $campaign->lines_available = null;
}

这是在将条目保存在控制器中之前完成的。

I fixed it by doing the following:

if ($_REQUEST['lines_available'] == 0) {
    $campaign->lines_available = null;
}

This is done before the entry is saved within the controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文