Tuesday, November 29, 2011

How to change WHERE statement for SQL Select.

I know why it's not working, I just cannot figure out how to fix it.

These are my errors:
1. Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id'
in 'where clause'
2. SQL Query: SELECT `Period`.`period_id`, `Period`.`title`,
`Period`.`created`, `Period`.`modified`, `Period`.`user_id` FROM
`periods` AS `Period` WHERE `id` = '51' AND `user_id` = 1 LIMIT 1

The query should be: .... WHERE 'period_id' = '51' AND 'user_id' = 1
LIMIT 1

I am doing the request from /periods/delete/51

Here is my PeriodsController.php

function delete($id) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}

if($this->isActionable($id)){
if ($this->Period->delete($id)) {
$this->Session->setFlash('Work successfully deleted.');
$this->redirect(array('controller' => 'posts', 'action' =>
'index'));
}
} else {
$this->Session->setFlash('You cannot delete that post.');
$this->redirect(array('controller' => 'posts', 'action' =>
'index'));
}
}

This is in my view Students/index.ctp:

$this->Form->postLink(
'Delete Class',
array('controller' => 'students', 'action' =>
'delete', $ps['Period']['period_id']),
array('confirm' => 'Are you sure?'));

-----------

I'm sure it's something obvious, but I am having a real difficult time
figuring it out. Thanks!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: