Datenbank-Fehler: Doppelter Eintrag
Den Fehler:
Einen Datenbank Fehler Aufgetreten
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', ' ', '', '')
Mein 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 */
Anderen Seite:
<?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;
} */
}
?>
Du musst angemeldet sein, um einen Kommentar abzugeben.
Scheint es, Ihre primary key-Spalte ist nicht
auto-incrementing
. So Ihre erste Platte hat eine 0 drin. Deine neue Platte nicht geben Sie einen Wert für den primary key so sind Sie das einfügen eines doppelten Primärschlüssels 0. Fügen Sie die Struktur der Tabelle hier bitte.Ich hatte ähnliche Fehler, wenn ich nur gepostet Pfad ohne Dateinamen zu mysql, sobald ich veröffentlicht den vollständigen Pfad und Dateinamen zusammen, er entledigte sich des Fehlers.
Versuchen: