When doing an insert, you need to call Model->create() first. And if you are calculating a value, assign is back to the request, so it can be saved on the Model.
On Thursday, 12 December 2013 16:18:56 UTC+10, YOONG SINJIE wrote:
-- $data1 = (string) $this->request->data['Calculate' ]['var1']; $data2 = (string) $this->request->data['Calculate' ]['var2']; $result = $data1 + $data2;
$this->request->data['Calculate']['result'] = $result;
$this->request->data['Calculate']['otherField'] = 2;
$this->Calculate->create();
if ($this->Calculate->save($this->request->data)){
echo 'Successful add';
}
On Thursday, 12 December 2013 16:18:56 UTC+10, YOONG SINJIE wrote:
May I know , got other way to store the SQL statement, except the Save() function ? I want to do some simple calculation, i want to store the result at database. Anyone having any idea about it ?public function add() { if ($this->request->is('post')) {
/// complete calculation $data1 = (string) $this->request->data['
Calculate' ]['var1']; $data2 = (string) $this->request->data['Calculate' ]['var2']; echo $data1; echo '<br/>'; echo $data2; $result = $data1 + $data2; echo '<br/>'; echo $result; SQL Statement mysql_query("INSERT INTO calculate VALUES('$data1','$data2','$result','2')" ) or die(mysql_error()); // if($this->Calculate->save($this->request->data)){ // echo'succuful add'; // } }}
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment