title: mysql php insert multiple rows with comma delimited values
body: <p>I have an html page where I collect an array of values from checkboxes to insert in a database. The html page posts to a PHP page that collects the data and then stores in the database.</p>
  
  <p>For each value, there are a few other fields I would like to include that are the same for all the values such as time entered.  I can easily convert the captured array into a comma delimited list using implode.  I use such a comma delimited list of ids to update and delete records.  However, when I want to insert them, MYSQL does not seem to allow you to use a comma delimited list.  My question is, what is the easiest way to insert records, one for each value in the c comma delimited list, without using a loop.</p>
  
  <p>html page</p>
  
  <pre><code>&lt;input type="checkbox" name="var[]" value=1&gt;
  &lt;input type="checkbox" name="var{}" value=2&gt;
  </code></pre>
  
  <p>PHP page</p>
  
  <pre><code>$vars = $_POST['var'];
  </code></pre>
  
  <p>This gives me an array that I can convert to a comma delimited list using implode.</p>
  
  <p>To delete, I can go</p>
  
  <pre><code>$sql = "DELETE * from table WHERE id in '$vars'";
  </code></pre>
  
  <p>To update I can go</p>
  
  <pre><code>$sql = "UPDATE table, WHERE id in '$vars'";
  </code></pre>
  
  <p>But there does not seem to be an equivalent for Insert.</p>
  
  <p>Following would work:</p>
  
  <pre><code>$sql = "INSERT into table (var, timeentered) values (1,now()) (2,now())";
  </code></pre>
  
  <p>However, that's not how I have my data.  what I would like to do is something like</p>
  
  <p><code>$sql = "INSERT into table (var,timeentered) values($vars), now()"</code> but of course that doesn't work. </p>
  
  <p>Do I have to convert my nice comma delimited list that works so well for update and delete into something that looks like (1,now) (2, now()) for inserting or is there an alternative?</p>
  
  <p>Thanks for any suggestions.</p>