如何解决此 Zend_Form_Element_Select 数据库错误?

发布于 2024-08-12 17:05:14 字数 2653 浏览 8 评论 0原文

当我将 Zend_Form_Element_Select 元素与多选项一起使用时,当我将所选值传递给 Zend_DB_Table 以插入数据库时​​,我收到此错误,

Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_status ' in 'field list'

我提取了一些我相信会出现的代码片段说明我的问题还有很长的路要走。我的表格中存在 accounts_status 字段确实

在我的表单构造中添加了 select 元素和选项(我省略了其他元素)

    $optionsstatus = array(
                    'active' => 'active',
                    'pending' => 'pending'              
                    );
    $optionsrole = array(
                'guest' => 'guest',
                'user' => 'user',
                'writer' => 'writer',
                'admin' => 'admin'              
                );

    $status = new Zend_Form_Element_Select('accounts_status');
                     $status->setLabel('Status')
                    ->setRequired(true)             
                    ->addMultiOptions($optionsstatus);
    $role = new Zend_Form_Element_Select('accounts_role');
                     $role->setLabel('Role')
                    ->setRequired(true)
                    ->addMultiOptions($optionsrole);

我使用 Zend_DB_table 从我的控制器插入后值

public function addaccount($username, $fullname, $email,
        $password,$status,$roles,$comments)
    {
        $data = array(
                'accounts_username' => $username,
                'accounts_fullname' => $fullname,
                'accounts_email' => $email,
                'accounts_password' => $password,               
                'accounts_status ' => $status,
                'accounts_roles' => $roles,             
                'accounts_comments ' => $comments,
        );
        $this->insert($data);
    }

在我的控制器中,我获取后值并将它们发送到我的模型

$username = $form->getValue('accounts_username');
                $fullname = $form->getValue('accounts_fullname');
                $email = $form->getValue('accounts_email');
                $password = $form->getValue('accounts_password');
                $status = $form->getValue('accounts_status');
                $roles = $form->getValue('accounts_roles');
                $comments = $form->getValue('accounts_comments');
                $accounts = new Model_DbTable_Account();
                $accounts->addaccount($username, $fullname,$email,
                $password,$status,$roles,$comments);

这种方法对我有用,除了在处理 Zend_Form_Element_Select elements.我只是想知道在 CRUD 操作方面是否有处理此选择元素的特定方法。

When i use the Zend_Form_Element_Select elements with multioptions i get this error when i pass the selected value to Zend_DB_Table to insert into the db

Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_status ' in 'field list'

I have extracted some code snippets that i believe will go a long way into illustrating my problem.The accounts_status field DOES exist in my table

On my form construct have added the select element and options (I have left out the other elements)

    $optionsstatus = array(
                    'active' => 'active',
                    'pending' => 'pending'              
                    );
    $optionsrole = array(
                'guest' => 'guest',
                'user' => 'user',
                'writer' => 'writer',
                'admin' => 'admin'              
                );

    $status = new Zend_Form_Element_Select('accounts_status');
                     $status->setLabel('Status')
                    ->setRequired(true)             
                    ->addMultiOptions($optionsstatus);
    $role = new Zend_Form_Element_Select('accounts_role');
                     $role->setLabel('Role')
                    ->setRequired(true)
                    ->addMultiOptions($optionsrole);

I use the Zend_DB_table to insert the post values from my controller

public function addaccount($username, $fullname, $email,
        $password,$status,$roles,$comments)
    {
        $data = array(
                'accounts_username' => $username,
                'accounts_fullname' => $fullname,
                'accounts_email' => $email,
                'accounts_password' => $password,               
                'accounts_status ' => $status,
                'accounts_roles' => $roles,             
                'accounts_comments ' => $comments,
        );
        $this->insert($data);
    }

In my controller i get the post values and send them to my model

$username = $form->getValue('accounts_username');
                $fullname = $form->getValue('accounts_fullname');
                $email = $form->getValue('accounts_email');
                $password = $form->getValue('accounts_password');
                $status = $form->getValue('accounts_status');
                $roles = $form->getValue('accounts_roles');
                $comments = $form->getValue('accounts_comments');
                $accounts = new Model_DbTable_Account();
                $accounts->addaccount($username, $fullname,$email,
                $password,$status,$roles,$comments);

This approach works for me except when am dealing with the Zend_Form_Element_Select elements.Am just wondering if there is a specific way of dealing with this select elements when it comes to CRUD operations.

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

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

发布评论

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

评论(1

夜访吸血鬼 2024-08-19 17:05:14
Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_status ' in 'field list'

也许我疯了,但在我看来,'accounts_status' 字段名称的末尾有一个额外的空格。

Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'accounts_status ' in 'field list'

Maybe I'm crazy, but looks to me like there's an extra space on that end of that 'accounts_status ' field name.

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