Codeigniter A Database Error Occurred Error Number 1062
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and codeigniter handle duplicate entry error policies of this site About Us Learn more about Stack Overflow the
Codeigniter Query Error Handling
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users duplicate entry for key primary 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 Database Error Occurred Error Number: 1062 up vote 0 down vote favorite i tried to make option update three table with one execution for my CI with sql there, but why its still error? this is the error warning: A Database Error Occurred Error Number: 1062 Duplicate entry '0' for key 1 UPDATE `t_publisher` SET `id_publisher` = NULL, `publisher` = NULL, `artis` = NULL, `id_label` = NULL WHERE `id_publisher` = '113' this is the code: function update($id_user=null) { if (($this->input->post('submit') == 'Update')){ $user=$this->input->post('username'); $pass=$this->input->post('userpassword'); $ussta=$this->input->post('userstatus'); $usty=$this->input->post('usertype'); $data = array( 'user_name' => $user, 'user_pass' => $pass, 'user_status' => $ussta, 'user_type' => $usty); $this->db->where('user_id', $this->input->post('id'), $data); $this->db->update("t_user",$data); $data1 = array( 'id_publisher' => $id_publis, 'publisher' => $publis, 'artis' => $ar, 'id_label' => $id_lab); $this->db->where('id_publisher', $this->input->post('id'), $data); $this->db->update("t_publisher",$data1); echo $this->db->last_query(); die(); $data2 = array( 'id_label' => $id_lab, 'label' => $label); $this->db->where('id_label', $this->input->post('id'), $data); $this->db->update("t_label",$data2); echo $this->db->last_query(); die(); redirect("registrasi/reg"); } $var['data'] = $this->db->query("select * from t_user where USER_ID= '$id_user'")->row_array(); $var1['data'] = $this->db->query("select * from t_publisher where id_publisher = '$id_publis'")->row_array(); $var2['data'] = $this->db->query("select * from t_label where id_label = '$id_lab'")->row_array(); $this->load->view('update', $var,$var1,$var2); } whats wrong with my code? please help. thanks before. mysql codeigniter sql-update share|improve this question asked Nov 12 '12 at 3:22 user1781895 616 You should post the CREATE TABLE statement. –Chris Henry Nov 12 '12 at 3:26 have you set your primary key as auto increment –raheel shan Nov 12 '12 at 5:59 dear Chris Henry,
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 more about Stack Overflow the company Business Learn more about hiring developers 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 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 up vote http://stackoverflow.com/questions/13337968/database-error-occurred-error-number-1062 3 down vote favorite 1 I'm getting the following error while executing database query: Error Number: 1062 Duplicate entry '1' for key 1 INSERT INTO `message_template` (`id`, `name`, `subject`, `detail`, `type`, `status`, `create_date`) VALUES (1, 'adaa', '', 'dss', 'SMS', 'Active', '2011-08-25 19:34:08') Filename: C:\AppServ\www\ci\system\database\DB_driver.php Line Number: 330 How can I get the error number (e.g. 1062) to handlle error? Thank you php sql codeigniter error-handling share|improve this http://stackoverflow.com/questions/7190446/handle-database-error-in-codeigniter question edited Aug 25 '11 at 13:11 J0HN 14.4k22669 asked Aug 25 '11 at 12:35 chenka 3737 add a comment| 1 Answer 1 active oldest votes up vote 8 down vote accepted That's an error coming from database. You can hide in /application/config/database.php $db['default']['db_debug'] = FALSE; Else, you might want to take care of it. I suggest just checking if the value already exists: $this->db->where('id', $id); $query = $this->db->get('message_template'); $data = array( 'id' => $id, 'name' => $name, 'subject' => $subject, 'detail' => $detail, 'type' => $type, 'status' => $status, 'create_date' => $create_date ); if($query->num_rows() > 0) { // the line already exists, so update $this->db->where('id', $id); $this->db->update('message_template', $data); } else { $this->db->insert('message_template', $data); } or, if you have the will to use raw queries, that should be slightly faster (I wouldn't really worry about a search by ID) $sql = "INSERT INTO message_template (id, name, subject, detail, type, status, create_date) VALUES (1, " + $this->db->escape($name) + ", " + $this->db->escape($subject) + ", " + $this->db->escape($detail) + ", " + $this->db->escape($type) + ", " + $this->db->escape($status) + ", " + $this->db->escape($create_date) + ") ON DUPLICATE KEY UPDATE name=" + $this->db->escape($name) + ", subject=" + $this->db->escape($subject) + ", d
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 http://stackoverflow.com/questions/22877227/codeigniter-a-database-error-occurred About Us Learn more about Stack Overflow the company Business Learn more about http://expressionengine.stackexchange.com/questions/16943/error-number-1062-duplicate-entry-465628-for-key-primary hiring developers 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 community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up codeigniter A Database Error duplicate entry Occurred up vote 3 down vote favorite Can someone help me? I am a beginner and trying to make wearing CodeIgniter authentication, but when I try to make an error like this A Database Error Occurred Error Number: 1046 No database selected SELECT * FROM (`user`) WHERE `user_username` = 'amanda' AND user_passwordMD5("12345") = Filename: C:\xampp\htdocs\codeigniter\system\database\DB_driver.php Line Number: 330 thanx codeigniter share|improve this question edited Apr codeigniter a database 5 '14 at 6:13 Subodh Ghulaxe 8,75065380 asked Apr 5 '14 at 6:05 Revoir Hz 1816 can you please make sure you have setup database configuration in config/database.php file –user3470953 Apr 5 '14 at 6:08 Please refer to the Codeignitor documentation before jumping to the coding. –dikesh Apr 5 '14 at 6:13 did any of the answer work !!! –saurabh kamble Apr 5 '14 at 7:04 thank you for giving advice, I do not have any information about documentnya and practice that the less I understand –Revoir Hz Apr 5 '14 at 7:14 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote accepted Check the database.php file in application/config/ $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'root'; $db['default']['password'] = 'mypassword'; $db['default']['database'] = 'my_database'; // here is the database selection share|improve this answer answered Apr 5 '14 at 6:12 ReNiSh A R 1,57021232 I have tried it and then appear again error like this A Database Error Occurred Unable to select the specified database: authtentication Filename: C:\xampp\htdocs\codeigniter\system\database\DB_driver.php Line Number: 140 –Revoir Hz Apr 5 '14 at 7:15 have you specified
up log in tour help Tour Start 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 more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us ExpressionEngine® Answers Questions Tags Users Badges Unanswered Ask Question _ ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Error Number: 1062 Duplicate entry '465628' for key 'PRIMARY' up vote 0 down vote favorite Running into some serious issues with CartThrob. All of a sudden I am getting this error when I add an item to the cart and try to view cart or checkout: It was working last night and sometime over night it all fell apart. Running EE 2.7.1 and CT 2.4 Error Number: 1062 Duplicate entry '465628' for key 'PRIMARY' INSERT INTO `exp_cartthrob_cart` (`cart`, `timestamp`, `url`) VALUES ('K6gFe9V1QJccK0fvGNVsRc4QcUIo5mUg0bI7289zYbY/N0ro47KwIXg6Y/DjZd3cvPIUwv5Ddy5jqgR+tBmK92NivQ9Mdf9gs94x2hqxGlcv3qv1uE3haM2cJrF8POUPRjZRWaKB2tVkAo7ItGfaYep5TMlyLAMToDfoxnF6tK5Zx+zp+xJR/nzoxiDZqVF97XESOODptuToYVcP1TDJcKGXhWxlXEw0div/hGHrIHLkN/6txq2saXOqK6QomFXPK9+d5f1orLFXVvLOoRT/m4Nf9A+43zww872nhYgsgHFbMSwZRDYGIb3iGiQzTxPl2eawxfM/pf+dWO4sZ4Wq0v2InbCDQAjX4BHDlXDidr5TsgR45SKmAatklSKhs9IR8/zfENwD8ZRnm2cEyOWBpHh6JKf7DOu4tvzL3Qq3wdu2KetrB5Pha77NF+jYp8kgn6e4WwlGcUf/MQDxbcaG/zt9AF+1DJc4+Z++hAeTORu8rv/t5EZKvRIADeUeoPyPZH1C7OGR7Jt73iN2i8dET58v4pHNpeEeBsU6d2v5WoGYWUu+ZrSvbhneo7dSBZR/NgmoVTf4ev3OR27JfMV7Tlaxe4+W0lgerm/BsDpQaYW6jOGINudI6/T1AHzQspCzmbsh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