CodeIgniter Forums
You must use the SET method to update an entry - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: You must use the SET method to update an entry (/showthread.php?tid=2010)



You must use the SET method to update an entry - El Forum - 07-11-2007

[eluser]plasticated[/eluser]
I am creating a simple form to add data to my database. I have used the code demonstrated in the 20min blog tutorial as a basis. Everything was going great until I wrote the code that inserts the data. For some reason, I am getting an error telling me: 'You must use the SET method to update an entry'.

I have checked and double checked, and it's the same code used in the example. Eg:

Code:
function create_insert()
    {
        $this->db->insert('streams', $_POST);
        redirect('admin/create/');
    }

On the view page I have this:

Code:
<?php echo form_open('admin/create_insert');?>

<p>&lt;input type="text" name"title" /&gt;</p>
<p>&lt;input type="text" name"artist" /&gt;</p>
<p>&lt;input type="text" name"date" /&gt;</p>
<p>&lt;input type="text" name"filename" /&gt;</p>

<p>&lt;input type="submit" value="Create" /&gt;</p>

&lt;/form&gt;

Any ideas? Things were going so well up until this point! Sad


You must use the SET method to update an entry - El Forum - 07-17-2007

[eluser]Phil Sturgeon[/eluser]
Whnat exactly is the trouble? Do a print_r() on your post array to see if the values exist. If that shows all the values check for DB errors by outputting the error string.


You must use the SET method to update an entry - El Forum - 09-08-2008

[eluser]Unknown[/eluser]
I had this same problem after following the tutorial. i found this thread and followed the suggestion. While reviewing my table structure to ensure that all fields were named correctly in my form, I noticed that phpmyadmin by default sets new fields to not accept a null value. I was just clicking submit instead of going through the trouble of filling out my form during testing. Since I hadn't set up validation yet, which would have prettily bounced me back to the form, I got the set method error b/c the db wouldn't accept the null values.


You must use the SET method to update an entry - El Forum - 10-16-2008

[eluser]Unknown[/eluser]
Got the same problem. It was the NULL problem.


You must use the SET method to update an entry - El Forum - 10-16-2008

[eluser]dpgtfc[/eluser]
must build, database, by.... hand....


You must use the SET method to update an entry - El Forum - 10-16-2008

[eluser]Colin Williams[/eluser]
The User Guide also suggests against using $_POST directly in a model. I wouldn't have the model interface with user input at all. Just something to consider.


You must use the SET method to update an entry - El Forum - 04-28-2009

[eluser]Sixer[/eluser]
I got this problem when I was accidentally using db->update() with a full query instead of db->query().


You must use the SET method to update an entry - El Forum - 12-20-2009

[eluser]NachoLabs[/eluser]
I'm getting the same error. I checked the DB and all the fields were indeed set to not null, so i fixed it and am still getting the same error. Check out my code:
Code:
function item($id,$datos) {
        $q = $this->db->get_where('data', array('id' => $id));
        if(isset($datos)) {
            if($datos===false) {
                return $this->db->delete('data', array('id' => $id));
            } else {
                $this->db->set($datos);
                if($q->num_rows()>0) {
                    $this->db->where('id',$id);
                    $this->db->update('data'); // <---- i tracked the error to this line.
                } else {
                    $this->db->insert('data');
                }
            }
        } else {
            return $q->row();
        }
    }

halp!


You must use the SET method to update an entry - El Forum - 12-20-2009

[eluser]NachoLabs[/eluser]
Nevermind, the array i was passing was empty all the time *u_u


You must use the SET method to update an entry - El Forum - 03-02-2010

[eluser]uniq[/eluser]
[quote author="NachoLabs" date="1261352444"]I'm getting the same error. I checked the DB and all the fields were indeed set to not null, so i fixed it and am still getting the same error. Check out my code:
Code:
function item($id,$datos) {
        $q = $this->db->get_where('data', array('id' => $id));
        if(isset($datos)) {
            if($datos===false) {
                return $this->db->delete('data', array('id' => $id));
            } else {
                $this->db->set($datos);
                if($q->num_rows()>0) {
                    $this->db->where('id',$id);
                    $this->db->update('data'); // <---- i tracked the error to this line.
                } else {
                    $this->db->insert('data');
                }
            }
        } else {
            return $q->row();
        }
    }

halp![/quote]

$this->db->set($datos);
you trying to set an empty array