Error Number 1062 Codeigniter
Contents |
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 database error number 1062 this site About Us Learn more about Stack Overflow the company Business
Codeigniter Database Error
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask codeigniter error handling 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 handling Handle database error in CodeIgniter up vote 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)
Error Number 1054 In Codeigniter
to handlle error? Thank you php sql codeigniter error-handling share|improve this question edited Aug 25 '11 at 13:11 J0HN 14.5k22670 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->esca
here for a quick overview of the site Help Center Detailed answers error number 1146 in codeigniter to any questions you might have Meta Discuss the workings error number 1064 codeigniter and policies of this site About Us Learn more about Stack Overflow the company Business Learn
Error Number 1048 Codeigniter
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 http://stackoverflow.com/questions/7190446/handle-database-error-in-codeigniter 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 - Model - Duplicate Entry Alert up vote 1 down vote favorite made a simple subscription form submit email and city only email id http://stackoverflow.com/questions/21139432/codeigniter-model-duplicate-entry-alert i set unique but if email id is already in database it shows error i need to add alert here if data already in database alert to user but dont show the complete details like this. A Database Error Occurred Error Number: 1062 Duplicate entry 'abc@abc' for key 2 INSERT INTO users (email, city) VALUES ('abdullah@gaya.com', 'jeddah') Filename: /home/content/f/a/h/fahadghafoor/html/fahad/models/users_model.php Line Number: 12 Model file user_model.php $this->input->post('email'), 'city' => $this->input->post('city'), ); $insert = $this->db->insert('users', $new_member_insert_data); return $insert; }//create_member } Controller file user.php load->helper('form'); $this->load->helper('url'); $this->load->library('user_agent'); $this->load->library('form_validation'); } public function create_user() { // field name, error message, validation rules $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules('city', 'City', 'trim|required'); if ($this->form_validation->run() == FALSE) { if ($this->input->post
Number: 1062 HELP Thread Closed 0 Vote(s) - 0 Average 1 2 3 4 5 Thread Modes Error Number: 1062 HELP El Forum Unregistered #1 05-22-2014, 05:02 PM [eluser]maniking[/eluser] http://forum.codeigniter.com/thread-60660.html Hello Guyz Need Help This is error when i try to add duplicate country names. Error Number: 1062 Duplicate entry 'italy ' for key 'Country_Name_UNIQUE' INSERT INTO `country` (`fkContinent_id`, `Country_Name`, `Country_ShortName`, `Country_Url`, `Country_PageTitle`, `Country_MetaKeywords`, `Country_MetaDescription`, `Country_PageContent`, `Country_Ext`) VALUES ('11', 'italy ', '', 'italy-', '', '', '', '', '') Filename: C:\xampp\htdocs\score\system\database\DB_driver.php Line Number: 330 My Controller : Code: function add()
{
authenticate();
if(submitted())
{
$arr = explode(".", $_FILES['picture']['name']);
$_POST['Country_Ext'] = $ext = $arr[count($arr)-1];
$this->db->insert("country", $_POST);
$path = "images/country/{$_POST['Country_Url']}.{$ext}";
move_uploaded_file($_FILES['picture']['tmp_name'], $path);
redirect("admins/country/index/added");
}
$data['content'] = $this->load->view("admin/country/add", array(), true);
$this->load->view("admin/template", $data);
} i wanted to print this error msg on my page to avoid this sql error number 1062 error on page i m new please help Thanks El Forum Unregistered #2 05-23-2014, 08:40 AM [eluser]CroNiX[/eluser] Turn off db_debug in database config and use Code: $this->db->_error_message();
$this->db->_error_number(); Although you will no longer see error messages for any query with db_debug turned off and have to handle them all manually, which isn't a good idea. It would be much better to query to see if that value exists first and return error based on that, or insert if it doesn't. You are also doing something very dangerous by inserting $_POST directly with no data validation. Very insecure. All of CI's db "write" type statements (insert/update/etc) return a boolean FALSE if there is an error. Code: if ($this->db->insert("country", $_POST) === FALSE)
{
//there was an error on insert, do something
} El Forum Unregistered #3 05-23-2014, 09:14 AM [eluser]maniking[/eluser] Thanks for replay I will try now this code... And how I can make secure that $_POST data validation? Thanks El Forum Unregistered #4 05-23-2014, 09:21 AM [eluser]maniking[/eluser] I tryed this code but still same error coming.. My Controller : Code: function add()