2014-09-05 2 views
0

사용자를 추가하는 동안이 오류가 발생했습니다.Cake php SQLSTATE [42000] : 구문 오류 또는 액세스 위반 : 1064

나는보기가 adduser.ctp 나는 다음과 같은 기능

function AddEditValidate() { 
    $validate1 = array(
     "user_group_id" => array(
      'rule' => array('comparison', '!=', 0), 
      'message' => 'Please select group'), 
     'first_name' => array(
      'mustNotEmpty' => array(
       'rule' => 'notEmpty', 
       'message' => 'Please enter first name'), 
      'custom' => array(
       'rule' => 'alphaNumericSpace', 
       'message' => 'First name should be alphnumeric') 
     ), 
     'last_name' => array(
      'mustNotEmpty' => array(
       'rule' => 'notEmpty', 
       'on' => 'create', 
       'message' => 'Please enter last name'), 
      'custom' => array(
       'rule' => 'alphaNumericSpace', 
       'message' => 'Last name should be alphnumeric') 
     ), 
     'email' => array(
      'mustNotEmpty' => array(
       'rule' => 'notEmpty', 
       'message' => 'Please enter email', 
       'last' => true), 
      'mustBeEmail' => array(
       'rule' => array('email'), 
       'message' => 'Please enter valid email', 
       'last' => true), 
      'mustUnique' => array(
       'rule' => 'isEmailUnique', 
       'message' => 'This email is already registered', 
      ) 
     ), 
     'oldpassword' => array(
      'mustNotEmpty' => array(
       'rule' => 'notEmpty', 
       'message' => 'Please enter old password', 
       'last' => true), 
      'mustMatch' => array(
       'rule' => array('verifyOldPass'), 
       'message' => 'Please enter correct old password'), 
     ), 
     'password' => array(
      'mustNotEmpty' => array(
       'rule' => 'notEmpty', 
       'message' => 'Please enter password', 
       'on' => 'create', 
       'last' => true), 
      'complex' => array(
       'rule' => array('complexPassword'), 
       'message' => 'Password should be six characters long, which should have minimum one alphabet, one number and one special character', 
      ), 
     ), 
     'captcha' => array(
      'mustMatch' => array(
       'rule' => array('recaptchaValidate'), 
       'message' => ''), 
     ) 
    ); 
    $this->validate = $validate1; 
    return $this->validates(); 
} 

에 의해 확인

나는 사용자 모델에서

public function addUser() { 
    $userGroups = $this->UserGroup->getGroups(); 
    unset($userGroups[1]); 
    unset($userGroups[2]); 
    $this->set('userGroups', $userGroups); 
    if ($this->request->isPost()) { 
     $this->User->set($this->data); 
     if ($this->User->AddEditValidate()) { 
      $this->request->data['User']['email_verified'] = 1; 
      $this->request->data['User']['active'] = 2; 
      $this->request->data['User']['parent_id'] = $this->Session->read('logged_client_id'); 
      $salt = $this->UserAuth->makeSalt(); 
      $this->request->data['User']['salt'] = $salt; 
      $this->request->data['User']['temp_password'] = $this->request->data['User']['password']; 
      $this->request->data['User']['password'] = $this->UserAuth->makePassword($this->request->data['User']['password'], $salt); 
      if ($this->User->save($this->request->data, false)) { 
       $this->sendLoginEmail($this->request->data['User']); 
       $this->Session->setFlash(__('The user is successfully added'), 'success_flash'); 
       $this->redirect('/clientUsers/' . $this->Session->read('logged_client_id')); 
      } else { 
       $this->Session->setFlash(__('Problem in saving user information'), 'error_flash'); 
      } 
     } 
    } 
} 

이제이 기능을 가지고있는 사용자 컨트롤러 그게 내게 오류를 준다

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 'AddEditValidate' at line 1

SQL Query: AddEditValidate

도와주세요.

감사

+0

나는이 질문은 많은 시간을 요구하지만 내 문제가 해결되지 알고 있습니다. 사용자 컨트롤러에서 함수는 if ($ this-> AddEditValidate()) {} if ($ this-> AddEditValidatee()) {}를 시도하지만 나에게도 같은 오류가 발생하면 if ($ this-> AddEditValidate()) {}입니다. 여기 질문에 내가 AddEditValidatee 입력 실수입니다. 나는 AddEditValidate해야합니다 알아요. – Kamal

+0

맞춤법 검사를 사용하십시오. AddEditValidate가 아닌 AddEditValidatee를 사용하십시오. – Abhishek

+0

$ this-> request-> data가 아닌 $ this-> data를 사용하여 다른 사람들이 도울 수 있도록 질문을 편집하십시오. – Abhishek

답변

0

데이터베이스 콜 럼 이름은 버전 3.0에서 인용되지 않습니다. 필드 이름에 SQL 키워드를 사용하고 있습니다. 열의 이름을 바꿀 수없는 경우 식별자 인용을 사용하도록 설정해야합니다. book.cakephp.org에서

:

$conn->driver()->autoQuoting(true); 

By default CakePHP does not quote identifiers in generated SQL queries. The reason for this is identifier quoting has a few drawbacks:

  • Performance overhead - Quoting identifiers is much slower and complex than not doing it.
  • Not necessary in most cases - In non-legacy databases that follow CakePHP’s conventions there is no reason to quote identifiers.

If you are using a legacy schema that requires identifier quoting you can enable it using the quoteIdentifiers setting in your Configuration. You can also enable this feature at runtime:

When enabled, identifier quoting will cause additional query traversal that converts all identifiers into IdentifierExpression objects.

+0

대답에서 여기에 할 일을 설명하지 않고 외부 사이트에 연결하지 마십시오. 링크가 끊어지면 귀하의 의견은 쓸모 없게됩니다. – Alan

+0

문제의 원인을 설명하는 동안 실제 솔루션을 제공하지 않았습니다. 이것은 평판으로 추가 할 수있는 주석으로 더 적합합니다. 가능한 경우 명확한 자급 자족 솔루션을 제공하기 위해 응답을 '편집'하십시오. 할 수 없다면, SO는 이것을 "답변이 아닙니다"라고 삭제할 것입니다. – SherylHohman

관련 문제