Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9272449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:52:51+00:00 2026-06-18T15:52:51+00:00

I am a new cake php developer.I am trying to insert multiple record but

  • 0

I am a new cake php developer.I am trying to insert multiple record but i cant.My table Structure is given below:
Table Name :
agents

==============================================  
 id | Contact |  Name  |  email_add  | Address
==============================================   

Controller Code :

public function send_money()
    {
         $this->layout='agent';
         $this->Agent->create();
         $this->Agent->set($this->data);

         if(empty($this->data) == false)
            {
                    if($this->Agent->save($this->data))
                    {
                        $this->Session->setFlash('Information Added Successfully.');
                        $this->redirect('send_money');
                    }

            }
            else
            {
                $this->set('errors', $this->Agent->invalidFields());    
            }
    }

Model Code Is :

<?php
App::uses('AppModel', 'Model');
/**
 * Admin Login Model
 *
 */
 class Agent extends AppModel
 {
    public $name='Agent';
    public $usetables='agents';

    public $validate = array(

    'contact' => array(
    'contact_not_empty' => array(
        'rule' => 'notEmpty',
        'message' => 'Please Give Contact No',
        'last' => true
        ),
    ),

      'name' =>array(
      'rule' => 'notEmpty', // or: array('ruleName', 'param1', 'param2' ...)
      'allowEmpty' => false,
      'message'    => 'Please Enter Name.'
    ),

    'email_add' => array(
            'email_add' => array(
            'rule' => 'email',
            'allowEmpty' => true,
            'message' => 'Please Enter Valid Email',
            'last' => true
    )),



    );

 }

?>

Its not possible to insert records with this code.What should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:52:53+00:00Added an answer on June 18, 2026 at 3:52 pm

    Let me explain everything.

    First of all your html form must be looks like following.

    <?php echo $this->Form->create('User'); ?>
    <tr>
        <td>
            <?php
                echo $this->Form->input('User.0.address',array
                (
                    'div'   => null,
                    'label' => false,
                    'class' => 'span required'
                ));
            ?>
    
            <?php
                echo $this->Form->input('User.1.address',array
                (
                    'div'   => null,
                    'label' => false,
                    'class' => 'span required'
                ));
            ?>
    
            <?php
                echo $this->Form->input('User.2.address',array
                (
                    'div'   => null,
                    'label' => false,
                    'class' => 'span required'
                ));
            ?>
        </td>
        <td>
            <input type="submit" value="Add" >
        </td>
    </tr>
    <?php echo $this->Form->end(); ?>

    As you can see to save many record at same time using cakephp you must define it as above it will parse input fields as array this is cakephp convention.

    I mean User.0.address for first array element

    User.1.address for second array element

    User.2.address for third array element and so on.

    Now.

    In Controller file.

    <?php
        function add()
        {
            $this->User->saveAll($this->data['User']);
        }

    And yes here you are done saving multiple record at same time.

    I just gave you how cakephp works all you need to do is set above hint as per your need.

    Best of luck…

    Cheers…

    Feel Free to ask… 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to Cake PHP framework and was trying few things in
I'm trying to import existing Cake 1.2 projects into PHP Eclipse (latest all-in-one download
I'm trying to edit a record in the database, but the script gives me
The cake php validation 'isUnique' gives error on edit var $validate = array( 'name'
I am new to cake php and I have a plugin folder in my
I am new to Cake PHP and I had a website with regular PHP
I am new to Cake PHP, in regular PHP I had a index.php and
I have a (cake) php function designed to update entries in a MySQL table;
Hi i am new in cake php and can't solve the problem. The problem
I'm new to an existing Cake project where we are trying to use a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.