• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error message 1062

hi after inserting records to my database .i encountered error message 1062.. duplicate entries..

i managed not to display the error and display "already exist" using
if (mysql_error()){
echo "exist"}

i was wondering how i can do that the active record way.. thanks.

any help would be greatly appreciated..

how can i do that without disabling error reporting?how can i do that without disabling error reporting?

Try using something like:

if($this->db->insert('mytable', $data){
  //successfully insert
  //Something wrong happened.

My guess if you are getting a duplicate entry, is that you have a set a column (id) to be the primary index, but either have not set the field to autoincrement. Or the other maybe that you are trying to add the primary key to the array you are trying to insert as a row, when it should be omitted.

but the error message still appears..

i set the value of the error reporting into false. and that takes care of the problem. is there any way not to display the error message without setting the error reporting value into false?

Try updating your table and checking "affected_rows()".

If the "affected_rows()" is zero then it is safe to assume that the record does not exist and you can insert your data:

define('jj', '<br />');
  $data = array(
               'title' => 'Whatever you are trying to append',

  // modify WHERE to a suitable condition
  $this->db->where('id', 123456789);
  $this->db->update('your_table', $data);

  echo jj, $this->db->last_query();
  echo jj, $this->db->affected_rows();
  echo jj, $this->db->insert_id();



thanks john.. now i know how to redirect a user when he encounter an error message. thanks!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.