title: sending multiple records to MySQL from multiple select box
body: <p>I'm trying to insert multiple rows into a MySQL table depending on the number of options selected from a multiple select box. currently it is inserting one row (regardless of how many options are selected) but the 'strategyname' column is empty each time. </p>
  
  <p>Any ideas on how to insert multiple rows and why the values of the options aren't being sent to the table?</p>
  
  <p>Here is the form:</p>
  
  <pre><code>&lt;form method="POST" action="update4.php"&gt;
  
  &lt;input type="hidden" name="id" value="1"&gt;
  
  &lt;p class="subheadsmall"&gt;Strategies&lt;/p&gt;
  
  &lt;p class="sidebargrey"&gt;
  
  &lt;?php
  
              $result = mysql_query("SELECT strategyname FROM sslink WHERE study_id = '{$_GET['id']}'");
                  if (!$result) {
                      die("Database query failed: " . mysql_error());
                  }
  
  while($row = mysql_fetch_array($result)) {
      $strategyname = $row['strategyname'];
  
  
      echo $strategyname.'&lt;br /&gt;';
  }
  
  ?&gt;
          &lt;p class="subheadsmall"&gt;Add a strategy... (hold down command key to select more than one)&lt;/p&gt;
  
  &lt;select name="strategylist" multiple="multiple"&gt;
       &lt;?php
  
              $result = mysql_query("SELECT * FROM strategies");
                  if (!$result) {
                      die("Database query failed: " . mysql_error());
                  }
  
  while($row = mysql_fetch_array($result)) {
      $strategylist = $row['name'];
      $strategyname = htmlspecialchars($row['name']);
      echo '&lt;option value="' . $strategylist . '" &gt;' . $strategyname . '&lt;/option&gt;' . '\n';
  }
  
  ?&gt;
  &lt;/select&gt;
      &lt;/p&gt;
  
  
  
  &lt;input type="submit" class="box" id="editbutton" value="Update Article"&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>And this is what sends it to the database:</p>
  
  <pre><code>&lt;?php
  $id=$_POST['id'];
  $test=$_POST['strategylist'];
  $db="database";
  
  $link = mysql_connect("localhost", "root", "root");
  //$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
  if (! $link)
  die("Couldn't connect to MySQL");
  mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
  //for($i=0;$i&lt;sizeof($_POST["test"]);$i++)
  //{
  //$sql = "insert into tbl_name values ($_POST["test"][$i])"; }
  //sql = "INSERT INTO table_name VALUES ('" . join(",",$_POST["test"]) . "')";
  $result=mysql_query("INSERT INTO sslink (study_id, strategyname) VALUES ('$id','" . join(",",$_POST["strategylist"]) . "')")or die("Insert Error: ".mysql_error());
  mysql_close($link);
  print "Record added\n";
  ?&gt;
  </code></pre>