Welcome Guest, Not a member yet? Register   Sign In
error message 1062
#1

[eluser]Near[/eluser]
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
Code:
if (mysql_error()){
echo "exist"}

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

any help would be greatly appreciated..
#2

[eluser]Near[/eluser]
how can i do that without disabling error reporting?how can i do that without disabling error reporting?
#3

[eluser]pickupman[/eluser]
Try using something like:

Code:
if($this->db->insert('mytable', $data){
  //successfully insert
}else{
  //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.
#4

[eluser]Near[/eluser]
thanks.
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?
#5

[eluser]John_Betong_002[/eluser]
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:

Code:
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();

  die;

&nbsp;
&nbsp;
#6

[eluser]Near[/eluser]
thanks john.. now i know how to redirect a user when he encounter an error message. thanks!
Code:
SOLVED




Theme © iAndrew 2016 - Forum software by © MyBB