Error Number 1062 Duplicate Entry 0 For Key Primary Codeigniter
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions
Error 1062 23000 Duplicate Entry 0 For Key Primary
you might have Meta Discuss the workings and policies of this mysql error 1062 duplicate entry for key primary site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers integrity constraint violation 1062 duplicate entry 0 for key primary or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Sqlstate 23000 Integrity Constraint Violation 1062 Duplicate Entry 0 For Key Primary
community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Codeigniter Error Duplicate entry '' for key 'PRIMARY' when looping insert statement up vote 0 down vote favorite I'm setting this function up in codeigniter to run as a cron job and log all
1062 Duplicate Entry 1 For Key Primary
users out at X time. I've used this code succesfully when selecting one user and logging that user out, but when adding the foreach, I get the following error: Error Number: 1062 Duplicate entry '3858' for key 'PRIMARY' INSERT INTO `time` (`id`, `projectid`, `phaseid`, `firstname`, `timest`, `status`, `activityid`, `todate`, `remark`, `time`, `workperiod`, `activitydate`, `entrydate`) VALUES ('3858', '212132 Unilever Nigeria  10000L Toothpaste Storage Tanks x 2', '1', 'BONGANI', '1347610976', '1', '1', '1', '1', 3335907, 'nothing', '2012-09-14 10:22:56', '2012-10-23 01:01:23') Filename: C:\xampp\htdocs\projectfiles\protime\v2\system\database\DB_driver.php Line Number: 330 This is the code for the model: function punch_out() { $this -> load -> database(); $this -> load -> helper('date'); //get people $this -> db -> select('*'); $this -> db -> from('person'); $this -> db -> order_by("department", "asc"); $this -> db -> order_by("userid", "asc"); $query = $this -> db -> get(); foreach ($query->result_array() as $row) { $people[] = $row; } foreach ($people as $row) : $this -> db -> from('punch'); $this -> db ->
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn codeigniter ignore duplicate entry error more about Stack Overflow the company Business Learn more about hiring developers or posting
Duplicate Entry 1 For Key Primary Codeigniter
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Duplicate entry '0' for key 'PRIMARY' in CodeIniter up vote http://stackoverflow.com/questions/13021328/codeigniter-error-duplicate-entry-for-key-primary-when-looping-insert-state 0 down vote favorite In CodeIgniter I need to insert an appointment information. Now the problem's that each appointment could have more service associated. So for fix this I've think to create for one appointment multiple row, for example: Appointment details service: cut , color How you can see there are two service associated, so in my database I'll have two row like this: id| name | service http://stackoverflow.com/questions/33712850/duplicate-entry-0-for-key-primary-in-codeiniter 10 appointment cut 10 appointment | color now instead of cut and color in my implementation there's a number, 'cause I've another table with all service details. This is my code that allow me to insert the appointment in my table: $appuntamento = $appointment; unset($appuntamento['id_services']); foreach($appointment['id_services'] as $id) { $appuntamento['id_services'] = $id; if(!$this->db->insert('ea_appointments', $appuntamento)) { throw new Exception('Error.'); } $insert_id = intval($this->db->insert_id()); } return $insert_id; In this function I pass the parameter appointment, I clone the appointment object in appuntamento object 'cause I need to loop through each service available in the appointment. In fact should there be so many lines of the same date in table, as the number of services associated? I'm executing an unset of the id_services 'cause it's an array and as I said I need to insert the same appointment for each service associated. So in the foreach I set the index id_services of my appuntamento variable. So I insert the object, the structure is like this: INSERT INTO `ea_appointments` (`id_users_provider`, `start_datetime`, `end_datetime`, `notes`, `is_unavailable`, `id_users_customer`, `book_datetime`, `hash`, `id_services`) VALUES ('85', '2015-11-14 22:00:00', '2015-11-14 22:00:00', '', 0, '87', '2015-11-14 12:00:33', '7a7e195d47b22cfd795f1876b3d2711b', '15') but I get this error: Duplicate entry '0' for key 'PRIMARY' In my database table I
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn http://stackoverflow.com/questions/14250221/handle-database-error-in-codeigniter-error-number-1062 more about Stack Overflow the company Business Learn more about hiring developers or http://forum.codeigniter.com/thread-1274.html posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Handle database error in CodeIgniter [Error Number: 1062] up duplicate entry vote 0 down vote favorite I'm getting the following error while executing database query: A Database Error Occurred Error Number: 1062 Duplicate entry '1' for key 'PRIMARY' UPDATE tbl_galeri SET id_galeri = '1', galeri_kat_id = '1', nama = 'Elyza Okiliyandass', foto = 0, deskripsi = 'Elyza Okiliyanda' Filename: C:\xampp\htdocs\indonesiausher\system\database\DB_driver.php Line Number: 330 Controller: $pilih['id_galeri'] = $this->uri->segment(3); $dt_galeri = $this->app_model->getSelectedData("tbl_galeri",$pilih); foreach($dt_galeri->result() as $db) { $bc['id_galeri'] = $db->id_galeri; $bc['galeri_kat_id'] = for key primary $db->galeri_kat_id; $bc['nama'] = $db->nama; $bc['foto'] = $db->foto; $bc['deskripsi'] = $db->deskripsi; $bc['stts'] = "edit"; } $this->load->view('backend/gallery/bg_input_usher',$bc); } Model: public function getSelectedData($table,$data) { return $this->db->get_where($table, $data); } How to handle this error? Thanks.. database codeigniter share|improve this question edited Jan 10 '13 at 5:53 asked Jan 10 '13 at 3:07 firewalls 309 1 Does your table have an id column? –Joseph Silber Jan 10 '13 at 3:10 Yap, i have table: 'tbl_galeri' with id: 'id_galeri' set to primary & auto increment. –firewalls Jan 10 '13 at 3:23 Are you sure it's set to auto increment? –Joseph Silber Jan 10 '13 at 3:28 Absolutely sure. So, how? :) –firewalls Jan 10 '13 at 4:06 2 Why is the error returning an update query but you're showing us code for what should be a select query. Please give us the model function for getSelectedData. –Rick Calder Jan 10 '13 at 4:26 | show 2 more comments 2 Answers 2 active oldest votes up vote 0 down vote Once try by removing the id_galeri like below in UPDATE Query UPDATE tbl_galeri SET galeri_kat_id = '1', nama = 'Elyza Okiliyandass', foto = 0, deskripsi = 'Elyza Okiliyanda' WHERE id_galeri
0 Vote(s) - 0 Average 1 2 3 4 5 Thread Modes sometimes get error Duplicate entry for key 'PRIMARY' karnadi Junior Member Posts: 2 Threads: 1 Joined: Nov 2014 Reputation: 0 #1 02-24-2015, 12:21 PM A Database Error Occurred Error Number: 1062 Duplicate entry '8873c26193f493433c2107eabf5b0629730d1428' for key 'PRIMARY' INSERT INTO `asni_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('8873c26193f493433c2107eabf5b0629730d1428', '127.0.0.1', 1424801434, '') Filename: libraries/Session/drivers/Session_database_driver.php Line Number: 216 should i remove PRIMARY key from field 'id' .... ?? Find Reply Narf Me Posts: 1,045 Threads: 0 Joined: Oct 2014 Reputation: 76 #2 02-24-2015, 01:25 PM (This post was last modified: 02-24-2015, 01:25 PM by Narf.) No, but if you want to use 'sess_match_ip', you must add a unique constraint for id, ip_address ... like explained in the manual: http://www.codeigniter.com/userguide3/li...ase-driver Find Reply matbeard Junior Member Posts: 9 Threads: 4 Joined: Feb 2015 Reputation: 0 #3 02-26-2015, 05:49 AM I'm having the same problem. It seems to be happening on ajax calls, but only over slow connections, perhaps when there is a delay between the initial page content loading and the ajax call being fired. I'm not using IP address verification, so it's nothing to do with that. I only noticed the problem when testing a site locally (the basabase is hosted on Amazon RDS though) whilst also uploading a video to YouTube, thus slowing the connection. The worry is that this issue would affect other users on slow connections. Find Reply karnadi Junior Member Posts: 2 Threads: 1 Joined: Nov 2014 Reputation: 0 #4 02-26-2015, 11:50 AM (02-24-2015, 01:25 PM)Narf Wrote: No, but if you want to use 'sess_match_ip', you must add a unique constraint for id, ip_address ... like explained in the manual: http://www.codeigniter.com/userguide3/li...ase-driver it works ... thank you ... Code: PRIMARY KEY (`id`),
UNIQUE INDEX `id_ip_address` (`id`, `ip_address`),
INDEX `timestamp` (`timestamp`)
) Find Reply -------------------- Private Messages User Control Panel Who's Online Search Forum Home General -- News & Discussion -- Lounge -- Events -- Regional User Groups Using CodeIgniter -- Choosing CodeIgniter -- Installation & Setup -- Model-View-Controller -- Libraries & Helpers -- Best Practices -- General Help CodeIgniter 4 -- CodeIgniter 4 Development -- CodeIgniter 4 Feature Requests -- CodeIgniter 4 Support -- CodeIgniter 4 Discussion Development