gpt4 book ai didi

sql - 数据库错误 : Duplicate Entry

转载 作者:行者123 更新时间:2023-11-29 05:43:53 27 4
gpt4 key购买 nike

错误:

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', ' ', '', '')

我的代码:

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

最佳答案

您的主键列似乎不是自动递增。所以你的第一条记录里面有一个 0。您的新记录没有为主键指定值,因此您插入了一个重复的主键 0。请在此处粘贴表的结构。

关于sql - 数据库错误 : Duplicate Entry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4393666/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com