Hi,
In cakephp I cant edit a row from my mysql db but I can add a new row on the same table without error.
Not sure what to do or how to debug this. The edittutorsession function is the problem
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'setFlash' at line 1
public function addtutorsession() {
$te= $this->Tutorsession->Teacher->find('list', array('fields' => 'Teacher.fullname'));
$this->set( 'te',$te);
$this->set( 'st',$this->Tutorsession->Student->find('list', array('fields' => array('Student.fullname') )));
if ($this->request->is('post')) {
$this->Tutorsession->create();
if ($this->Tutorsession->save($this->request->data)) {
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'displayall'));
}
$this->Session->setFlash(__('Unable to add your post.'));
}
}
public function edittutorsession($id = null) {
$te= $this->Tutorsession->Teacher->find('list', array('fields' => 'Teacher.fullname'));
$this->set( 'te',$te);
$this->set( 'st',$this->Tutorsession->Student->find('list', array('fields' => array('Student.fullname') )));
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Tutorsession->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
if ($this->request->is(array('post', 'put'))) {
$this->Tutorsession->id = $id;
if ($this->Tutorsession->save($this->request->data)) {
$this->Tutorsession->setFlash(__('Your post has been updated.'));
return $this->redirect(array('action' => 'displayall'));
}
$this->Session->setFlash(__('Unable to update your post.'));
}
if (!$this->request->data) {
$this->request->data = $post;
}
}
///////////////
view edittutorsession
<?php
echo $this->Form->create('Tutorsession');
echo $this->Form->input('teacher_id', array('options' => $te));
echo $this->Form->input('student_id', array('options' => $st));
echo $this->Form->input('subject'); //text
echo $this->Form->input('sessiondate',
array('label' => 'Session'));
echo $this->Form->input('sessiontime',
array('label' => 'time'));
echo $this->Form->input('available');
echo $this->Form->end('Save Post');
?>