Hi Everybody,

*I. mysql db*
users table with id username and password field.

*II. index.ctp*
<div class="login">
<h2>Login</h2>
    <?php echo $form->create('Post', array('action' => 'login'))?>
        <?php echo $form->input('username');?>
        <?php echo $form->input('password');?>
        <?php echo $form->submit('Login');?>
  <?php echo $form->button('Reset', array('type'=>'reset',
'action'=>'clearLogin'));?>
    <?php echo $form->end(); ?>
</div>

*III. posts_controller.php*
function login()
 {
  if(empty($this->data) == false)
        {
            if(($user = $this->Post->validateLogin($this->data['username']))
== true)
            {
                $this->Session->write('Post', $user);
                $this->Session->setFlash('You\'ve successfully logged in.');
                $this->redirect('main');
                exit();
            }
            else
            {
                $this->Session->setFlash('Sorry, the information you\'ve
entered is incorrect.');
                exit();
            }
        }
 }
 function clearLogin()
 {
  $this->data['Post']['username'] = '';
  $this->data['Post']['password'] = '';
 }
 function logout()
 {
  $this->Session->destroy('user');
  $this->Session->setFlash('You\'ve successfully logged out.');
        $this->redirect('index');
 }
*IV. Model*
function validateLogin($data)
    {
        $user = $this->find(array('username' => $data['username'],
'password' => $data['password']), array('id', 'username'));
        if(empty($user) == false)
            return $user['User'];
        return false;
    }


*Finally my error is,*


Notice (8): Undefined index:  username
[APP\controllers\posts_controller.php, line 60]

Code

        if(empty($this->data) == false)

        {

            if(($user =
$this->Post->validateLogin($this->data['username'])) == true)

PostsController::login() - APP\controllers\posts_controller.php, line 60
Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 227
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 194
[main] - APP\webroot\index.php, line 88

Warning (512): SQL Error: 1054: Unknown column 'Post.username' in 'field
list' [CORE\cake\libs\model\datasources\dbo_source.php, line 525]

Code | Context

$sql = "SELECT `Post`.`id`, `Post`.`username` FROM `posts` AS `Post`   WHERE
`username` IS NULL AND `password` IS NULL    LIMIT 1"
$error = "1054: Unknown column 'Post.username' in 'field list'"
$out = null

            $out = null;
            if ($error) {
                trigger_error("<span style =
\"color:Red;text-align:left\"><b>SQL Error:</b>
{$this->error}</span>", E_USER_WARNING);

DboSource::showQuery() - CORE\cake\libs\model\datasources\dbo_source.php,
line 525
DboSource::execute() - CORE\cake\libs\model\datasources\dbo_source.php, line
201
DboSource::fetchAll() - CORE\cake\libs\model\datasources\dbo_source.php,
line 337
DboSource::read() - CORE\cake\libs\model\datasources\dbo_source.php, line
647
Model::find() - CORE\cake\libs\model\model.php, line 1963
Post::validateLogin() - APP\models\post.php, line 38
PostsController::login() - APP\controllers\posts_controller.php, line 60
Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 227
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 194
[main] - APP\webroot\index.php, line 88

Query: SELECT `Post`.`id`, `Post`.`username` FROM `posts` AS `Post`   WHERE
`username` IS NULL AND `password` IS NULL    LIMIT



*Help me to solve this issue*
**
*How do i change the sq query to my table.*
**
*Regards,*
*Dhileepen*

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to