after your save statement.. $var = $this->Contact->lastInsertId();
On Mon, Oct 25, 2010 at 7:48 AM, macha <[email protected]> wrote: > Hello I am using cakePHP 1.3 and I am unable to retreive the last > inserted row's id. I actually am using $this->Model->id to retreive > the last inserted id but I am unable to get the id. When tried to > check what is return type, it says as bool(false), which means nothing > is returned. > > Here I am loading a different model in a different controller, so > would that be the issue?? But even though I am loading, I get back > nothing!! > > $this->loadModel('Contact'); > $this->Contact->query("insert into > > contacts(tblContact_firstName,tblContact_lastName,tblContact_company,tblContact_department,tblContact_address,tblContact_country,tblContact_city,tblContact_state,tblContact_zipcode,tblContact_phone1,tblContact_email1) > > values('$sanitizedFormData[fname]','$sanitizedFormData[lname]','','$sanitizedFormData[company]','$sanitizedFormData[address]','$sanitizedFormData[country]','$sanitizedFormData[city]','$sanitizedFormData[state]','$sanitizedFormData[zip]','$sanitizedFormData[phone]','$sanitizedFormData[email]');"); > > $this->loadModel('Contact'); > $contactId = $this->Contact->id; > > And when I printed the $this->Contact array recursively, I found the > value of "id" key empty. So that explains why I was receiving an empty > value. > > Now given my situation, how would I get the last inserted id, specific > to the controller Contact?? Is it possible? > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<cake-php%[email protected]>For > more options, visit this group at > http://groups.google.com/group/cake-php?hl=en > Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] 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
