title: insert values from checkbox in table using php + mysqli
body: <p>I have 3 tables (actors, categories, actor_cats) in my db. </p>
  
  <p>I'm using a form to insert new info in the database (mysql). Most of the information goes into the actors table.
  But in a label "categories", i have a checkbox input type, with 3 fields that i get from the categories table [action (id1), comedy(id2), drama(id3)]. I want to insert this information in my actor_cats table.
  What i want to do is create a new actor in actors table, and also insert the checkbox selection (might be all 3 options) in the actors_cats table. This table as the actors id and the categories id, so what i want would be something like this:</p>
  
  <p>Table actor_cats</p>
  
  <p>row 1 | actorid (1) | categoriesid (1)</p>
  
  <p>row 2 | actorid (1) | categoriesid (2)</p>
  
  <p>as an example...</p>
  
  <p>how can i achieve this using mysqli?</p>
  
  <p>thanks in advance!</p>
  
  <p>I still can't write to the actor_cats table. This is what i'm doing:</p>
  
  <p>//After inserting the new actor</p>
  
  <pre><code>$jid = $mysql-&gt;insert_id;
  
  if (isset($_POST['cats'])) {
  $cats = $_POST['cats'];
  } else {
  $cats = array();
  }   
  $numCats = 0;
  foreach ($cats as $catID) {
  
  $cats_sql = "INSERT INTO actor_cats VALUES(?,?)";    
  $stmt = $mysql-&gt;stmt_init();
  
  if ($stmt-&gt;prepare($cats_sql)) {
  $stmt-&gt;bind_param('ii', $jid, $catID);
  $stmt-&gt;execute();
  
      if ($ok) {
        $numCats = $numCats + 1;
      } else {
        echo "&lt;p&gt;Error inserting $catID: " .
            $mysql-&gt;error . '&lt;/p&gt;';
  
      } 
    }
  
  &lt;?php
  else:
  $cats = 'SELECT id, type FROM categories';
  $stmt = $mysql-&gt;prepare($cats);
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($catid,$cattype);
  </code></pre>
  
  <p>?></p>
  
  <p>And in my form in the checkbox area, i fetch my categories table and get the values, so when i submit the form, my selection would be inserted</p>
  
  <pre><code> //excerpt from form
   &lt;label&gt;Category:&lt;/label&gt;&lt;br /&gt;
   &lt;?php while($row = $stmt-&gt;fetch()) :  ?&gt; 
    &lt;input type="checkbox" name="cats" value="&lt;?php echo $catid; ?&gt;" /&gt;&lt;?php echo $cattype;   ?&gt;
   &lt;br /&gt;&lt;br /&gt;   &lt;?php  endwhile; ?&gt;
  </code></pre>
  
  <p>Hope this is clear!
  Thanks all the guys for all the help!</p>