2010-12-09 12 views
1

오류가 :데이터베이스 오류 : 중복 된 항목

A Database Error Occurred Error Number: 1062 Duplicate entry '0' for key 1

INSERT INTO `CCI_Faculty` 
    (`Username`, `Password`, `LastName`, `FirstName`, `Title`, `Phone`, `Email`, `Office`, `Department`, `Biography`, `Website`, `CV`) 
VALUES 
    ('terry12', 'feba90aa365c150fccecca6dc8024696', 'stewart', 'carl', 'dean', '778-990-0002', '[email protected]', 'UCB771', 'IT', ' ', '', '') 

내 코드 :

<?php 
    class CCI extends Controller { 

function CCI() 
{ 
    parent::Controller(); 
} 

function index() 
{ 

     $this->load->helper('url'); 
     $this->load->view('Users/login'); 

} 



function register() 
{ 

     $this->load->helper('url'); 
     $this->load->view('Registration/Register_Main'); 
} 

function cci_users() 
{ 
    $this->load->helper(array('form','url')); 

    $this->load->library('form_validation'); 

    if(isset($_POST['username'])&& isset($_POST['password'])&& 
        isset($_POST['last_name'])&& isset($_POST['first_name'])&& 
        isset($_POST['title'])&& isset($_POST['number'])&& 
        isset($_POST['office'])&& isset($_POST['department'])); 

    $this->form_validation->set_rules('username','Your Username', 
        'required|alpha_numeric|min_length[6]|max_length[44]'); 
    $this->form_validation->set_rules('password','Your Password', 
        'required|alpha_numeric|min_length[12]|max_length[24]'); 


    $this->form_validation->set_rules('last_name','Last Name', 
        'required|alpha_numeric'); 
    $this->form_validation->set_rules('first_name','First Name', 
        'required|alpha_numeric'); 

    $this->form_validation->set_rules('title','Job Title', 
        'required|alpha_numeric'); 
    $this->form_validation->set_rules('number',' Phone', 
        'required'); 

    $this->form_validation->set_rules('office',' Office', 
        'required'); 
    $this->form_validation->set_rules('department',' Department', 
        'required'); 

    if ($this->form_validation->run() === TRUE) 
     { 
      $this->load->model('CCI_Employee'); 

      $data['rows'] = $this->CCI_Employee->cci_new_users($_POST['username'], 
          $_POST['password'],$_POST['last_name'],$_POST['first_name'], 
          $_POST['title'],$_POST['number'],$_POST['email'], 
          $_POST['office'],$_POST['department'],$_POST['bio'], 
          $_POST['website'],$_POST['cv']); 

      $this->load->view('profile', $data); 

     } 
     else 

     $this->load->view('Registration/Register_Main'); 


} 

function print_profile() 
{ 
    $this->load->helper('url'); 

    $this->load->model('CCI_Employee'); 
    $data['rows'] = $this->data_model->cci_new_users(); 

    $this->load->view('profile', $data); 
} 
} 

/* End of file cci.php */ 
/* Location: ./system/application/controllers/cci.php */ 

다른 페이지 :

<?php 
class CCI_Employee extends Model { 

function CCI_Employee() 
{ 
parent::Model(); 

$this->load->database(); 
} 

function validate_users($username, $password) 
{ 

    $password = md5($password); 

    $search_login = 
    $this->db->get_where('CCI_Faculty', array('Username'=> $username)); 

    if($search_login->num_rows() > 0) 
    { 
     if($password == $search_login->row()->password) 
     return TRUE; 

     else 

     return FALSE; 
    } 
    else 

     return FALSE; 

} 

function cci_new_users($username, $password, $last_name, $first_name, $title, 
               $number, $email, $office, $department, $bio, $website, 
               $cv) 
{  
     $username = $this->input->post('username'); 
     $password = md5($this->input->post('password')); 
     $last_name = $this->input->post('first_name'); 
     $first_name = $this->input->post('last_name'); 
     $title = $this->input->post('title'); 
     $number = $this->input->post('number'); 
     $email = $this->input->post('email'); 
     $office = $this->input->post('office'); 
     $department = $this->input->post('department'); 
     $bio = $this->input->post('bio'); 
     $website = $this->input->post('website'); 
     $cv = $this->input->post('cv'); 

    $insert = $this->db->insert('CCI_Faculty', array('Username' => $username, 
      'Password' => $password, 'LastName' => $last_name, 
      'FirstName' => $first_name, 'Title' => $title, 'Phone' => $number, 
      'Email' => $email, 'Office' => $office, 'Department' => $department, 
      'Biography'=> $bio, 'Website' => $website, 'CV' => $cv)); 

      $this->db->select('FirstName, LastName, Title, Phone, Email, Office, 
               Department, Biography, Website, CV'); 

      $check_insert = $this->db->get('CCI_Faculty'); 

      return insert; 


     if($check_insert->num_rows() > 0) 
     { 
     foreach ($check_insert->result()as $row) 
     { 
      $data[] = $row; 
     } 
     return $data; 
     } 
} 

/** $user_info = "SELECT LastName, FirstaName, Department, Phone, Email, Office 
           FROM CCI_Faculty WHERE LastName = ? AND FirstName = ? AND 
           Department = ? AND Phone = ? AND Email = ? AND Office = ?"; 
    $retrieve = $this->db->query($user_info, $new_users('last_name','first_name', 
          'department','number','website','office')); 

    if($retrieve->num_rows() > 0) 
    { 
     foreach ($retrieve->result() as $row) 
     { 
      $data[] = $row; 
     } 
     return $data; 
    } */ 
} 
?> 

답변

4

그것은 당신의 기본 키 열 보인다는 auto-incrementing 아니다 . 첫 번째 기록에는 0이 들어 있습니다. 새 레코드는 기본 키 값을 지정하지 않으므로 중복 기본 키를 0으로 삽입합니다. 여기 테이블 구조를 붙여 넣으십시오. 내가 함께이 오류를 제거있어 전체 경로와 파일 이름을 게시하면 난 단지, MySQL의에 파일 이름없이 경로를 게시 할 때 비슷한 오류가 발생한

REPAIR TABLE <TABLE_NAME>;