[eluser]Stromgren[/eluser]
Hey CI users
Im currently working on a form which causes me some problems..
Problably me having some troubling figuring out whats arrays and objects in this..
Anyways.. First of all i have a table filled with interests that people can check off in the form.
The table has two columns, ID and NAME.
So i fetch my interests and in my view i make my checkboxes like this
Code:
<?php foreach($interests->result() as $interest): ?>
<?php echo form_checkbox('interest[]', $interest->id, FALSE); echo $interest->name; ?>
<?php endforeach; ?>
In the controller i recieve the data like this:
Code:
$interests = $this->input->post('interest');
And then i send it, along with some other data, to my model:
Code:
$this->Registration_model->register_user($username, $email, $password, $country, $city, $interests, $setup, $job, $bio, $activation_code);
Now in the model i recieve a user_id from the query which writes all the data except the interests. Now i want to write to another table, users_interests, a row for each interest checked. This row should contain a user_id and a interest_id.
Code:
...
$user_id = mysql_insert_id();
foreach($interests as $interest)
{
$int_id = $interest->id;
$query = "INSERT INTO users_interests (user_id, int_id) VALUES (?, ?)";
$this->db->query($query, array($user_id, $int_id));
}
When i run this i get this error:
Quote:Error Number: 1048
Column 'int_id' cannot be null
INSERT INTO users_interests (user_id, int_id) VALUES (29, NULL)
So the int_id is empty. As i said, im problably mixing something up when using arrays and objects, but i cant seem to fix this..
Any help is apprecieted
Thanks in advance