Tuesday, November 10, 2009

Re: Edit form attempting INSERT INTO statement and fails

It turns out I did have a mix of cases. Sorted that out now thanks. Have another issue though:

When I try to add a new entry for my page's comments, I am returned to the main page (which is what I want), but the main page is blank!? I then have to refresh the page (usually I can only do it by pressing "Go" to load the page again) to get the information to show. The comment is added, but for some reason the page is blank. Here is the code for the index page:



<h1>Comments</h1> 
  <?php echo $html->link('Add Comment',array('controller' => 'comments', 'action' => 'add')); ?>

<table> 
   <tr> 
       <th>ID</th> 
       <th>Name</th>  
       <th>Date</th>
   </tr> 
   <?php foreach ($comments as $comment): ?> 
   <tr> 
       <td><?php echo $comment['Comment']['id']; ?></td> 
       <td> 
           <?php echo $html->link($comment['Comment']['name'], "/comments/view/".$comment['Comment']['id'])?>   
     [<?php echo $html->link('Edit', array('action' => 'edit', 'id' => $comment['Comment']['id']));?> |  
     <?php echo $html->link('Delete', "/comments/delete/".$comment['Comment']['id'], null, 'Are you sure?')?>]  
       </td>
       <td><?php echo $comment['Comment']['com_date']; ?></td> 
 </tr> 
   <?php endforeach; ?> 
</table>




and this is the code for the add page:

<h1>Add Comment</h1> 

   <?php
   echo $form->create('Comment');
   echo $form->input('name'); //text
   echo $form->input('com_date');
   echo $form->input('comment', array('rows' => '3'));
   echo $form->end('Add Information');
   ?>



On Mon, Nov 9, 2009 at 8:34 PM, O.J. Tibi <ojtibi@gmail.com> wrote:

Hi,

I'm guessing your primary key field is misspelled? You could try
replacing ID with id (lower case).

Cheers,
OJ

On Nov 10, 2:26 am, dpinion <dpin...@gmail.com> wrote:
> Greetings,
> I am a bit new to cake, and am diving in via the cookbook. I have a
> simple app I am trying to develop, and am modifying the cookbook
> example to fit it. So far everything has worked great with one
> exception. I have an edit form that when I go to it it fills in with
> the DB data from the record previously selected (on the index page).
> However, once I change any information and try to submit it, I receive
> the following:
>
> SQL Error: 1062: Duplicate entry '1' for key 1 [CORE/cake/libs/model/
> datasources/dbo_source.php
>
> The query string tells me that the form is attempting to perform an
> INSERT Into instead of an UPDATE command on the database, causing the
> failure. I am not sure why it is doing this... Here is my edit.ctp
> content:
>
> <h1>Edit Comment</h1>
>
>    <?php
>    echo $form->create('Comment', array('action' => 'edit'));
>    echo $form->input('name'); //text
>    echo $form->input('com_date'); //day, month, year, hour, minute,
> meridian
>    echo $form->input('comment', array('rows' => '3'));
>    echo $form->input('ID', array('type' => 'hidden'));
>    echo $form->end('Update Information');
>    ?>
>
> and here is the edit section from the controller:
>
> function edit($id = null) {
> $this->Comment->id = $id;
>    if (empty($this->data))
>    {
>        $this->data = $this->Comment->read();
>    }
>    else
>    {
>        if($this->Comment->save($this->data))
>        {
>             $this->Session->setFlash('Your comment has been updated.
> ','/comments/');
>        }
>    }
>
> }
>
> any suggestions as to what I am doing wrong?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---




--
Dewayne Pinion
Web/Software Guy
Trenton Technology
http://www.trentontechnology.com

--

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cake-php?hl=.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate