• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem passing data to model.


Im currently doing a registration form but i got some problems.

In my registration view i've got a couple og checkboxes like this:

<?php foreach($interests->result() as $interest): ?>
<?php echo form_checkbox('interest[]', $interest->id, FALSE); echo $interest->name; ?>
<?php endforeach; ?>

The interests are stored in a table with an ID and a Name column.

In the controller the data is recieved like this:

$username = $this->input->post('username');
$email = $this->input->post('email');
$password = $this->input->post('password');
$country = $this->input->post('country');
$city = $this->input->post('city');
$interests = $this->input->post('interest');
$setup = $this->input->post('setup');
$job = $this->input->post('job');
$bio = $this->input->post('bio');
$activation_code = $this->Registration_model->random_string(10);
$this->Registration_model->register_user($username, $email, $password, $country, $city, $interests, $setup, $job, $bio, $activation_code);

And the registration model looks like this:

function register_user($username, $email, $password, $country, $city, $interests, $setup, $job, $bio, $activation_code)
$sha_password = sha1($password);
$query = "INSERT INTO users (username, email, password, country, city, setup, job, bio, activation_code, activated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$this->db->query($query, array($username, $email, $sha_password, $country, $city, $setup, $job, $bio, $activation_code, 0));
$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));

Now in the foreach statement i want to create a row in users_interests table containing the interest ID and the user ID for every interest checked, but i seems i am recieving the information incorrectly?

Can anyone help?
Thanks in advance..

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.