Welcome Guest, Not a member yet? Register   Sign In
Having issue with updating database
#1

[eluser]ZeroNine[/eluser]
I been trying to stay away from posting up this issue since it seems like such a simple fix but I can't seem to figure it out and I been pulling my hair out with this.


Code:
function update_invites_table($inv_id,$pid)
    {
       $this->db->where('id',$inv_id);
       $this->db->set('invited_pid',$pid);
       $this->db->update('invites');
    }

$pid is an integer and the field invited_pid is set to int(11) but the column will not update with this number. What is sooo odd is that this works:

Code:
function update_invites_table($inv_id,$pid)
    {
       $this->db->where('id',$inv_id);
       $this->db->set('invited_pid','23');
       $this->db->update('invites');
    }

Also this works too

Code:
function update_invites_table($inv_id,$pid)
    {
       $pid = '23';
       $this->db->where('id',$inv_id);
       $this->db->set('invited_pid',$pid);
       $this->db->update('invites');
    }

BUT if I do this
Code:
function update_invites_table($inv_id,$pid)
    {
       $this->db->where('id',$inv_id);
       $this->db->set('invited_pid',$pid);
       $this->db->update('invites');
       echo $pid;
    }

$pid will echo 23 but the column does not update. What can possibly be going on here?
#2

[eluser]InsiteFX[/eluser]
Because update and insert expect an associated array!
Code:
$data = array(
    'invited_pid' => $pid
);

$this->db->where('id', $inv_id);
$this->db->update('invites', $data);

Also you do not need to set the values it will do it.
#3

[eluser]Matalina[/eluser]
@InsiteFX: While you are correct it can take an array, you can use set() to do the same thing.

Code:
$this->db->set('name', $name);
$this->db->set('title', $title);
$this->db->set('status', $status);
$this->db->insert('mytable');

Quote:You may also use the $this->db->set() function described above when performing updates.

Taken Straight from documentation.

@ZeroNine: Are you sure you are adding the correct data type to the database. is '23' and 23 are not the same.
#4

[eluser]InsiteFX[/eluser]
Sure can using an extra lines of code that are not needed!
#5

[eluser]Matalina[/eluser]
but that isn't what you said. You said it expects an associative array. Not that their code was bloated.
#6

[eluser]ZeroNine[/eluser]
[quote author="InsiteFX" date="1337957062"]Because update and insert expect an associated array!
Code:
$data = array(
    'invited_pid' => $pid
);

$this->db->where('id', $inv_id);
$this->db->update('invites', $data);

Also you do not need to set the values it will do it.
[/quote]

Yes I actually tried this way first and I had the same problem so I tried $this->db->set().
#7

[eluser]ZeroNine[/eluser]
[quote author="Matalina" date="1337960753"]@InsiteFX: While you are correct it can take an array, you can use set() to do the same thing.

Code:
$this->db->set('name', $name);
$this->db->set('title', $title);
$this->db->set('status', $status);
$this->db->insert('mytable');

Quote:You may also use the $this->db->set() function described above when performing updates.

Taken Straight from documentation.

@ZeroNine: Are you sure you are adding the correct data type to the database. is '23' and 23 are not the same.[/quote]

Thank you for your reply!
I changed the database field to VARCHAR to test that way and it still did not work.
#8

[eluser]Matalina[/eluser]
What's be replaced in there? I assume you aren't getting errors.

going to ask you a silly question. is the id valid?

I'm thinking that it's updating just not updating where you think it is.
#9

[eluser]ZeroNine[/eluser]
I should mention that $pid was first encoded and used as an email confirmation code
Example: http://mysite.com/confirm/WXTfrs+=.

And then in the controller it was decoded before being sent to the model as $pid.
Example: $pid = $this->encrypt->decode($pid_code);

Then sent over to the model..
Code:
$this->invite_model->update_invites_table($inv_id,$pid);
#10

[eluser]ZeroNine[/eluser]
[quote author="Matalina" date="1337968040"]What's be replaced in there? I assume you aren't getting errors.

going to ask you a silly question. is the id valid?

I'm thinking that it's updating just not updating where you think it is.[/quote]

You are correct, I am not getting any errors. After I run the script, the database field stays empty. Also if I were to manually input any number into the database field through phpmyadmin and then run the script, it will erase it completely and leave it blank or back to 0 depending on if the field is set to VARCHAR or INT.




Theme © iAndrew 2016 - Forum software by © MyBB