title: Passing an array via POST in PHP to be inserted into MySQL
body: <p>I have a form that allows users to input classes and activities into multiple fields, these fields are declared like this :</p>
  
  <pre><code>    label for ="classact"&gt;Classes and Activities&lt;/label&gt;
          &lt;input type = "text" name = "classact[0]" value ="" id ="classact[0]"&gt;
          &lt;input type = "text" name = "classact[1]" value ="" id ="classact[1]"&gt;
          &lt;input type = "text" name = "classact[2]" value ="" id ="classact[2]"&gt;
  </code></pre>
  
  <p>When the form is passed this is the code that handles in the insert:</p>
  
  <pre><code>    $maininsert = "INSERT INTO `camptest`
          (`name`, `city`, `phone`, `photo`)
          VALUES
          ('$_POST[name]', '$_POST[city]', '$_POST[phone]', '$photoinfo')
          SET @lid = LAST_INSERT_ID()
          ";
  
      $classactinsert = "INSERT INTO `class_act`
                  (`cid`";
  
      for($i = 0; $i &lt; 3; $i++)
      {
         if(isset($_POST['classact'][$i]))
         {
            $temp = $i+1; 
            $classactinsert = $classactinsert . ",`act$temp`";
         }
      }
  
     $classactinsert = $classactinsert . ")
                                  VALUES
                                  ('@lid'";
  
     for($i = 0; $i &lt; 3; $i++)
     {
        if(isset($_POST['classact'][$i]))
        {
           $classactinsert = $classactinsert . ",'$_POST[classact][$i]";
        }
     }
  
    $classactinsert = $classactinsert . ")";                                  
  
    $indata = $maininsert . $classactinsert;
  
    $result = mysql_query($indata);
  </code></pre>
  
  <p>I realize thats alot of code, but upon filling out the form and submitting this is the query that gets generated:</p>
  
  <pre><code>    INSERT INTO `camptest` (`name`, `city`, `phone`, `photo`) VALUES ('Multiple Activities', 'Nowhere', '555-555-1111', 'images/51127f6b06d1e.jpg') SET @lid = LAST_INSERT_ID() INSERT INTO `class_act` (`cid`,`act1`,`act2`,`act3`) VALUES ('@lid','Array[0],'Array[1],'Array[2])
  </code></pre>
  
  <p>The query is not inserting, but its not throwing back any errors either, even though I have them turned on.</p>
  
  <p>My main question is, what am I doing wrong that is causing the values to act1, act2, and act3 to show up as Array[0], Array[1], and Array[2]?</p>
  
  <p>My secondary question is, am I even going about this the right way? I'm a little new to php and I'm afraid I might be doing this the hard way?</p>
  
  <p>Any help would be appreciated, let me know if you need any additional information.     </p>