Controller
if ($this->request->is('post')) {
$a = $_POST['category'];
$b = $_POST['subcategory'];
$c = $_POST['category1'];
$d = $_POST['subcategory1'];
// i have checked whether values are comming to controller r not
echo $a;
echo $b;
echo $c;
echo $d;
//They are comming
// I have category and subcategory columns in my databse
// I want to store $a and $b in one row ,$c and $d values in the next row of my database .
// I have written like this
$this->Bill->create();
if ($this->Bill->save($this->request->data)) {
$this->Bill->saveField('category',$a);
$this->Bill->saveField('subcategory',$b);
$this->Bill->saveField('category',$c);
$this->Bill->saveField('subcategory',$d);
$this->Session->setFlash(__('The Bill has been saved'));
return $this->redirect(array('controller' => 'Bills','action' => 'view'));
}
$this->Session->setFlash(__('The bill could not be saved'));*/
}
// but $c and $d values are only storing in row.
How to store $a and $b in one row ,$c and $d values in the next row of my database ?
please help me ...!
May be you must create an object to each of them.
$bill_1=new Bill;
$bill_2=new Bill;
$this->Bill->create();
$bill_1->saveField('category',$a);
$bill_1->saveField('subcategory',$b);
$bill_2->saveField('category',$c);
$bill_2->saveField('subcategory',$d);
if($bill_1->save() && $bill_2->save()){
$this->Session->setFlash(__('The Bill has been saved'));
return $this->redirect(array('controller' => 'Bills','action' => 'view'));
}
$this->Session->setFlash(__('The bill could not be saved'));*/
I don't know how your method save the data. I just want to say that you must create an object to create a row. CMIIW.
You need to build an array of key value pair then save it in your database table
$data = array (
array(
'a' => $_POST['category'],
'b' => $_POST['subcategory']
),
array(
'a' => $_POST['category'],
'b' => $_POST['subcategory'],
),
);
Then pass the array to insert query. The root of the problem is how your data is coming out from the $_POST. It should have been formatted and sent as an array of key value pairs. Hope this help.