How to update existing records

The following code inserting as new record when i update the existing record. Is there any modification for below code, Please help.




if ( !in_array( $key, $restrict_insert_values ) ) {

                    if ( is_array( $value ) ) {

                        $key   = str_replace( "[]", "", $key );

						

                        $value = implode( "|", $value );

                    }

                    if ( !is_array( $value ) ) {

					

                        $frm_value                = new FormValues();

                        $frm_value->element_id    = $key;

                        $frm_value->form_values   = $value;

                        $frm_value->form_id       = $form_id;

                        $frm_value->form_entry_id = $form_total_entires;

						

                        $frm_value->save(false);


                    }

                }