Re: Updating a Record with an auto increment id
Hey, Sorry for the confusion. I just called it id_number when I was giving an example of the URL i meant id. Thanks for the help. You led me to my problem. mySQL didn't have a starting auto_increment set on the table. I altered it to 1. I altered the record with 0 as the id to be 1. I then ran the script again and the the query it ran was an update instead of a insert. Thanks for the help. This is my first cakePHP project and I'm really having a go at it adjusting to the intricacies of the system. On Jan 5, 8:14 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote: > On Jan 5, 2008 6:51 PM, Travis <[EMAIL PROTECTED]> wrote: > > > When I use $this->Customer->Save() this is the message I recieve ... > > > Query: INSERT INTO `customers` > > (`name`,`street`,`city`,`state`,`zip`,`phone`,`id`,`modified`,`created`) > > VALUES > > ('thomas','','Lafayette','LA','70517','337-555-','0','2008-01-05 > > 17:48:02','2008-01-05') > > > Warning (512): SQL Error: 1062: Duplicate entry '0' for key 1 [CORE/ > > cake/libs/model/datasources/dbo_source.php, line 440] > > Well, what jumped out at me right away was the fact that your 'id' > field is set to 0 in the statement above. So, because 'id' is 0, it > keeps trying to insert a record with an 'id' of 0, which I am assuming > is the primary key for that field. I'd also bet there is one record > in there with an 'id' of 0, hence SQL complaints about duplicate > entries. > > Now, bear with me here and please remember I am trying to help... > > You mention above that you have a field called 'id_number' that is > supposed to be the primary key for the table. Well, in the above > query I don't see any field called 'id_number'. So, that leads me to > think that the primary key for the table must be 'id'. > > In order for the update to work, you need to make sure that > $this->data['Customer']['id'] is set to some value because if it is > missing, then it looks like (to me anyway) that it is defaulting to 0. > > Tell me if that makes sense. > > -- > Chris Hartjes > Internet Loudmouth > Motto for 2008: "Moving from herding elephants to handling snakes..." > @TheKeyBoard:http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Updating a Record with an auto increment id
On Jan 5, 2008 6:51 PM, Travis <[EMAIL PROTECTED]> wrote: > When I use $this->Customer->Save() this is the message I recieve ... > > Query: INSERT INTO `customers` > (`name`,`street`,`city`,`state`,`zip`,`phone`,`id`,`modified`,`created`) > VALUES > ('thomas','','Lafayette','LA','70517','337-555-','0','2008-01-05 > 17:48:02','2008-01-05') > > Warning (512): SQL Error: 1062: Duplicate entry '0' for key 1 [CORE/ > cake/libs/model/datasources/dbo_source.php, line 440] > Well, what jumped out at me right away was the fact that your 'id' field is set to 0 in the statement above. So, because 'id' is 0, it keeps trying to insert a record with an 'id' of 0, which I am assuming is the primary key for that field. I'd also bet there is one record in there with an 'id' of 0, hence SQL complaints about duplicate entries. Now, bear with me here and please remember I am trying to help... You mention above that you have a field called 'id_number' that is supposed to be the primary key for the table. Well, in the above query I don't see any field called 'id_number'. So, that leads me to think that the primary key for the table must be 'id'. In order for the update to work, you need to make sure that $this->data['Customer']['id'] is set to some value because if it is missing, then it looks like (to me anyway) that it is defaulting to 0. Tell me if that makes sense. -- Chris Hartjes Internet Loudmouth Motto for 2008: "Moving from herding elephants to handling snakes..." @TheKeyBoard: http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Updating a Record with an auto increment id
I tried that, but it didn't resolve the problem. On Jan 5, 6:59 pm, Robby Anderson <[EMAIL PROTECTED]> wrote: > In your model declaration, did you use the primaryKey property? > > var $primaryKey = 'id_number'; > > On Jan 5, 5:51 pm, Travis <[EMAIL PROTECTED]> wrote: > > > HI, > > > I'm trying to update a record through the controller action customers/ > > edit/id_number. This loads a form prepopulated with the customer data > > associated with id_number. The form posts to customers/edit. > > > The id_number field is an auto increment integer that is the primary > > key on the table. When I try to call Save() or Update() in my > > controller, I get sql errors. Here's the latest attempt at my > > controller logic. Any advice would be appreciated ! > > > function edit($id = null){ > > if (empty($this->data)) > > { > > $this->Customer->id = $id; > > $this->data = $this->Customer->read(); > > } > > else > > { > > $this->Customer->save($this->data['Customer']); > > > $this->flash('Your customer data has been > > updated.', '/customers'); > > > } > > } > > > When I use $this->Customer->Save() this is the message I recieve ... > > > Query: INSERT INTO `customers` > > (`name`,`street`,`city`,`state`,`zip`,`phone`,`id`,`modified`,`created`) > > VALUES > > ('thomas','','Lafayette','LA','70517','337-555-','0','2008-01-05 > > 17:48:02','2008-01-05') > > > Warning (512): SQL Error: 1062: Duplicate entry '0' for key 1 [CORE/ > > cake/libs/model/datasources/dbo_source.php, line 440] > > > When I use $this->Customer->Update() this is the message I recieve > > > Query: update > > > Warning (512): SQL Error: 1064: You have an error in your SQL syntax; > > check the manual that corresponds to your MySQL server version for the > > right syntax to use near '' at line 1 [CORE/cake/libs/model/ > > datasources/dbo_source.php, line 440] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Updating a Record with an auto increment id
In your model declaration, did you use the primaryKey property? var $primaryKey = 'id_number'; On Jan 5, 5:51 pm, Travis <[EMAIL PROTECTED]> wrote: > HI, > > I'm trying to update a record through the controller action customers/ > edit/id_number. This loads a form prepopulated with the customer data > associated with id_number. The form posts to customers/edit. > > The id_number field is an auto increment integer that is the primary > key on the table. When I try to call Save() or Update() in my > controller, I get sql errors. Here's the latest attempt at my > controller logic. Any advice would be appreciated ! > > function edit($id = null){ > if (empty($this->data)) > { > $this->Customer->id = $id; > $this->data = $this->Customer->read(); > } > else > { > $this->Customer->save($this->data['Customer']); > > $this->flash('Your customer data has been updated.', > '/customers'); > > } > } > > When I use $this->Customer->Save() this is the message I recieve ... > > Query: INSERT INTO `customers` > (`name`,`street`,`city`,`state`,`zip`,`phone`,`id`,`modified`,`created`) > VALUES > ('thomas','','Lafayette','LA','70517','337-555-','0','2008-01-05 > 17:48:02','2008-01-05') > > Warning (512): SQL Error: 1062: Duplicate entry '0' for key 1 [CORE/ > cake/libs/model/datasources/dbo_source.php, line 440] > > When I use $this->Customer->Update() this is the message I recieve > > Query: update > > Warning (512): SQL Error: 1064: You have an error in your SQL syntax; > check the manual that corresponds to your MySQL server version for the > right syntax to use near '' at line 1 [CORE/cake/libs/model/ > datasources/dbo_source.php, line 440] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Updating a Record with an auto increment id
HI, I'm trying to update a record through the controller action customers/ edit/id_number. This loads a form prepopulated with the customer data associated with id_number. The form posts to customers/edit. The id_number field is an auto increment integer that is the primary key on the table. When I try to call Save() or Update() in my controller, I get sql errors. Here's the latest attempt at my controller logic. Any advice would be appreciated ! function edit($id = null){ if (empty($this->data)) { $this->Customer->id = $id; $this->data = $this->Customer->read(); } else { $this->Customer->save($this->data['Customer']); $this->flash('Your customer data has been updated.', '/customers'); } } When I use $this->Customer->Save() this is the message I recieve ... Query: INSERT INTO `customers` (`name`,`street`,`city`,`state`,`zip`,`phone`,`id`,`modified`,`created`) VALUES ('thomas','','Lafayette','LA','70517','337-555-','0','2008-01-05 17:48:02','2008-01-05') Warning (512): SQL Error: 1062: Duplicate entry '0' for key 1 [CORE/ cake/libs/model/datasources/dbo_source.php, line 440] When I use $this->Customer->Update() this is the message I recieve Query: update Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [CORE/cake/libs/model/ datasources/dbo_source.php, line 440] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: updating a record
basically you'd want to set $this->data['Model']['user_id'] = $this->Session->user_id (I forget correct Session syntax at the moment, but you ge tthe idea) - do this before your $this->Model->save($this->data) statement in your controller's "add" or "edit" methods in your "Edit" method do pretty much what you were saying - before you load the Model's data into your edit form, when you're querying the Model to populate, add something like '`Model`.`user_id` = "{$session_user_id}"' to your find() statement take a look at rdBloggery -> http://rd11.com/rdOS/ -> it uses a simple but handy authentication / permissions schema (rdAuth) and answers a lot of questions like yours --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
updating a record
Hi to all cake bakers, I am using session based authentication and I want to update a record based on information supplied on a form submission. If i use the standard save function, the record will be saved based on the id of the record i supply update some record WHERE ID = $ID The problem is that I want to update a record based on the id and the session_id update some recored WHERE ID = $ID and client_id = $SESSION_ID This ensures that each client can only update their own records in a table based on the session id. Seeing as how there is no update method in cake, how do i do this? Cheers. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---