Re: Another FormBuilder question

From: Date: Wed, 16 Feb 2005 01:08:07 +0000
Subject: Re: Another FormBuilder question
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17545@lists.php.net to get a copy of this message
On Feb 15, 2005, at 6:19 PM, Justin Patrin wrote:
On Tue, 15 Feb 2005 16:15:58 -0500, James Stewart <james@jystewart.net> wrote:
I've just been reworking some of the formbuilder code I was working on and asking questions about a couple of weeks ago and have run into a problem. I know I've encountered it before, but I can't remember how I got around it, which has been driving me crazy... I'm using the same function to build my form whether it's for editing a user or creating a new one. My code looks like (with relevant input validation elsewhere): $data = DB_DataObject::factory('users'); if (!empty($_GET['id'])) {
        // I've tested and this is only happening when it ought to be
        $data->get($_GET['id']);
} $ebuild =& DB_DataObject_FormBuilder::create($data); $form = $ebuild->getForm(); if ($form->validate()) {
        $form->process(array(&$ebuild,'processForm'), false);
        return;
} // Go on to output form and so on. The error I'm seeing is that when I create a new user the DataObject tries to insert it using an UPDATE query. ie: dataobjects_users: QUERY: UPDATE users SET user_name = 'James Stewart' , etc, etc, etc WHERE users.user_id = IS NULL Obviously this isn't working, but I can't remember why it's using UPDATE instead of INSERT in this instance.
What's your primary key for the table? If it's not an auto incremented field, this is likely your problem. You can "get around this" by using sequenceKey() on the DO to force your key to work. Check the archives for more. To really fix this I would suggest altering your table to have an auto incremented primary key. You can still have a unique username and such.
No, user_id is an auto incrementing primary key. From the DO:
    var $user_id;                         // int(11)  not_null primary_key auto_increment
James.

« previous php.pear.general (#17545) next »