Welcome Guest, Not a member yet? Register   Sign In
$this->db->upda_string() don't upadte the row
#1

[eluser]atoleon[/eluser]
Hi

I've got a code to update a row in my database but the code don't write on it. This is the code im using and i cant see the error.

Code:
$datos_usuario = array (
                                                'nombre' => $this->input->post('nombre'),
                                                'apellidos' => $this->input->post('apellidos'),
                                                'nif' => $this->input->post('nif'),
                                                'direccion' => $this->input->post('direccion'),
                                                'email' => $this->input->post('email'),
                                                'telefono' => $this->input->post('telefono')
                                            );
        $where = 'id_usuario = 1';
        $query = $this->db->update_string('usuarios', $datos_usuario, $where);
#2

[eluser]WanWizard[/eluser]
error message?

What is the result of
Code:
echo $this->db->last_query();
#3

[eluser]ShoKatoo[/eluser]
Try this:
Code:
$where = array('id_usuario' => '1');

Have Phun! Smile
#4

[eluser]atoleon[/eluser]
[quote author="WanWizard" date="1288040155"]error message?

What is the result of
Code:
echo $this->db->last_query();
[/quote]
the result of $this->db->last_query()is empty. It's like the query wasnt executed.

However echo $query return UPDATE `usuarios` SET `nombre` = 'Antonio Juan', `apellidos` = 'sv', `nif` = '', `direccion` = '', `email` = '[email protected]', `telefono` = '' WHERE id_usuario = 1

And if i execute this in my phpmyadmin, the row is updates.

Then, the problem must be the query is not executed in the code. But the code seems good.
#5

[eluser]WanWizard[/eluser]
I've never used this helper, so I looked it up in the manual.

That clearly states:
Quote:This function simplifies the process of writing database updates. It returns a correctly formatted SQL update string.

So it is absolutely correct that it doesn't execute anything, it just generates the SQL.

Why don't you use active record instead?
Code:
$this->db->where('id_usuario', '1');
$this->db->update('usuarios', $datos_usuario);




Theme © iAndrew 2016 - Forum software by © MyBB