Like grigri says, read the manual and use Cake functionality.

Below is your add function rewritten (completely untested of course)
to use Cake conventions:

function add(){
    $this->set('sections', $this->Entry->Section->find('list',array
 
('fields'=>'Section.section','Section.id')));
    if (!empty($this->data)){
         $this->Entry->create();
         if ($this->Entry->save($this->data)) {
             $this->Entry->id = $this->Entry->getLastInsertId();
             $max_counter = $this->Entry->find('list',
                                            array('fields' => array(
 
'(max(Entries.counter)) as max_counter')'
                                                                   )
                                                 )

                                              );
            $this->Entry->counter = $max_counter['Entry'][0]
['max_counter'];

            if(is_uploaded_file($this->data['Entry']['File']
['tmp_name'])){
               $fileData = fread(fopen($this->data['Entry']['File']
['tmp_name'],"r"),$this->data['Entry']['File']['size']);
               $this->Entry->name = $this->data['Entry']['File']
['name'];
               $this->Entry->size = $this->data['Entry']['File']
['type'];
               $fsize = $this->data['Entry']['File']['size'];
               $this->Entry->data = addslashes($fileData);

            }
            if ($this->Entry->save($this->data)){
                $this->Session->setFlash(__('The Entry '.$this->Entry-
>id.' was added and updated', true));
                $this->redirect(array('action' => 'index'));

            }  else {
                $this->Session->setFlash(__('The Entry could not be
updated. Please, try again.', true));
            }
        } else {
                $this->Session->setFlash(__('The Entry could not be
saved. Please, try again.', true));
        }
    }

}

On Jan 13, 5:37 am, mona <[email protected]> wrote:
> In my add view when i kept all the fields blank and click on submit
> button it will display a message record added successfully instead of
> that i wan't to display my validation message and page should not be
> redirect to other page
> how to do this here is my add function code
> --------------------------------------------add function in
> controller---------------------------------------------------
> function add(){
> $this->set('sections', $this->Entry->Section->find('list',array
> ('fields'=>'Section.section','Section.id')));
> if (!empty($this->data)){
> $this->Entry->save($this->data);
> $id=mysql_insert_id();
> if($id){
> $query=mysql_query("select max(counter) from entries");
> $row=mysql_fetch_array($query);
> $co=$row[0]+1;
> $q=mysql_query("update entries set counter=$co where id=$id");
> if(is_uploaded_file($this->data['Entry']['File']['tmp_name'])){
> $fileData = fread(fopen($this->data['Entry']['File']['tmp_name'],
> "r"),
> $this->data['Entry']['File']['size']);
> $fname = $this->data['Entry']['File']['name'];
> $ftype = $this->data['Entry']['File']['type'];
> $fsize = $this->data['Entry']['File']['size'];
> $fdata = addslashes($fileData);
> $q1=mysql_query("update entries set name='$fname',size=
> $fsize,type='$ftype',data='$fdata' where id=$id");}
> }
>
> $this->Session->setFlash('The Entry has been saved');
> $this->redirect('/entries/index');}
> }
>
> -------------------------------------------------my model code is
> ---------------------------------------------
> <?php
> class Entry extends AppModel{
>         var $name = 'Entry';
>         var $belongsTo=array('Section'=>array(
>         'className'=>'Section'
>         ),
>         'Submenu'=>array('className'=>'Submenu')
>         );
>         var $validate = array(
>         'username' => array('/^[a-zA-Z._0-9]+$/'),
>                 'Please enter username' => array('rule'=>'notEmpty'),
>                 'Listitem'=>array(
>                   'Please enter listitem' => array
> ('rule'=>'notEmpty')),
>                  'section_id'=>array(
>                   'Please select listitem' => array
> ('rule'=>'notEmpty')),
>                 'Telephone'=>array(
>                   'Please enter phone number' => array
> ('rule'=>'notEmpty'),
>                   'Must be at least 10 chars' => array('rule'=>array
> ('minLength', 10))),
>
>       );}
>
> ?>
>
> please tell me the answer it is very urgent
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to