Saturday, January 29, 2022

[FIXED] Codeigniter error message Duplicate entry

Issue

I'm trying to implement Php Codeigniter model function that can count the number of left children and the number of right children for binary tree but i got this message error :

Error Number: 1062

Duplicate entry '4' for key 1 INSERT INTO 'mytable' (members_id, members_username, members_password,)Filename: C:\AppServ\www\app\system\database\DB_driver.php

Line Number: 330

i use this function and i think i have some logic error .

function count(){
 $query = $this->db->get('mytable');
foreach ($query->result() as $row) {
 if ($row->id > 1) {
  $Right_Child= $this->insert_to_right($row, $row->id);
  $Left_child = $this->insert_to_left($row, $row->id);
$count1=0;
    $count2=0;
if($Left_child!=NULL){

        for($count1;$count1<=10;$count1++)

            {
       $count1=$htis->Left_child->count();
            echo 'Left_child';

        }
        if($Right_Child!=NULL){
            for($count2;$count2<=10;$count2++){
            $count2= $this ->Right_Child->count();

            return $count2;
            echo 'Right_Child';
            if($count1==$count2){
                echo'tree';

            }

            }
        }
    }

        }

Solution

What Amin Adha has pointed out is correct.

When you INSERT a record into the database, try to leave out the ID of the record, or, set it to NULL.

In this case, the ID field appears to be "members_id"

You have a problem with an insert somewhere.



Answered By - Naveed Hasan

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.