Welcome Guest, Not a member yet? Register   Sign In
You must use the SET method to update an entry
#1

[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
#2

[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.
#3

[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.
#4

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

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

[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.
#7

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

[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!
#9

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB