开发者

Database Error: Duplicate Entry

开发者 https://www.devze.com 2023-01-30 03:59 出处:网络
The Error: A Database Error Occurred Error Number: 1062 Duplicate entry \'0\' for key 1 INSERT INTO `CCI_Faculty`

The Error:

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', 'dea09@cci.edu', 'UCB771', 'IT', ' ', '', '')

My Code:

<?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 */

Other Page:

<?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;
    } */
}
?>


It seems your primary key column is not auto-incrementing. So your first record has a 0 in there. Your new record doesn't specify a value for the primary key so you're inserting a duplicate primary key of 0. Paste the structure of the table here please.


I had similar error when I only posted path without file name to mysql, once I posted the full path and file name together it got rid of the error.


Try to:

REPAIR TABLE <TABLE_NAME>;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号