数据库错误:重复的条目
问题描述:
的错误:数据库错误:重复的条目
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;
} */
}
?>
答
看来你的主键列不auto-incrementing
。所以你的第一个记录在那里有一个0。你的新记录没有为主键指定一个值,所以你插入了一个重复的主键0.请在这里粘贴表格的结构。
答
尝试:
REPAIR TABLE <TABLE_NAME>;
答
我有类似的错误,当我只贴不路径文件名到MySQL,一旦我贴的完整路径和文件名一起它摆脱了错误的。