Update does nothing

0

Use CodeIgniter and PHP. When doing an Update, no message is displayed and the update is not done.

client_search (controller):

public function mod(){      
    $mod=$this->main_model->mod(
        $this->input->post("DocIdent"),                                                                        
        $this->input->post("Nombre"),
        $this->input->post("Apellido"),
        $this->input->post("Direccion"),
        $this->input->post("Telefono"),
        $this->input->post("Estado"),
        $this->input->post("FechaIngreso"),
        $this->input->post("Password")
    );

    //si la actualización ha sido correcta creamos una sesión flashdata para decirlo
    if($mod){
        $this->session->set_flashdata('actualizado', 'Usuario modificado correctamente');                
    }else{
        $this->session->set_flashdata('incorrecto', 'No se pudo modificar el registro');
    }
}

main_model:

public function mod($DocIdent, $Nombre, $Apellido, $Direccion, $Telefono, $Estado, $FechaIngreso, $Password){   
    $losDatos = array(
        'Nombre' => $Nombre,
        'Apellido' => $Apellido,
        'Direccion' => $Direccion,
        'Telefono' => $Telefono,
        'Estado' => $Estado,
        'FechaIngreso' => $FechaIngreso,
        'Password' => $Password
    );
    $this->db->where('DocIdent', $DocIdent);
    return $this->db->update('tbl_cliente', $losDatos);
    if(is_object($query)){
        if($query->num_rows() == 1) { // if the affected number of rows is one
            return true;
        }
    } else {  
        return false;
    }
}

What should I modify?

The data comes null from this view

<!DOCTYPE HTML>
<html lang="es">
    <head>
        <meta charset="UTF-8" />
        <title>Modificar Cliente</title>
    </head>
    <body>
        <h2>Modificar Cliente</h2>

        <?php echo form_open("cliente_buscar/mod"); ?>         
            <?php foreach ($mod as $fila){ ?>
            <input type="text" name="docIdent" value="<?=$fila->DocIdent?>"/>
            <input type="text"  name="nombre" value="<?=$fila->Nombre?>"/>
            <input type="text" name="apellido" value="<?=$fila->Apellido?>"/>
            <input type="text" name="direccion" value="<?=$fila->Direccion?>"/>
            <input type="text" name="telefono" value="<?=$fila->Telefono?>"/>
            <input type="text" name="estado" value="<?=$fila->Estado?>"/>
            <input type="text" name="fechaIngreso" value="<?=$fila->FechaIngreso?>"/>
            <input type="text" name="password" value="<?=$fila->Password?>"/>
            <input type="submit" name="submit" value="Modificar"/>
            <?php } ?>
        <!-- </form> -->
        <?php echo form_close(); ?>
        <a href="<?=base_url()?>">Volver</a>
    </body>
</html>
    
asked by Jhon Hernández 09.10.2018 в 06:47
source

1 answer

0

What I mean is that the function db-> update returns true or false if it has been executed successfully or not. Therefore, you will have to enter a conditional and act accordingly.

if($this->db->update('tbl_cliente', $losDatos)){
   echo "Datos actualizados";
} else {
  echo "Se produjo un error al actualizar los datos";
}
    
answered by 10.10.2018 в 09:13