title: PHP/mysql: mysqli prepared statement insert same value multiple times within for loop
body: <p>I am using a prepared statement to insert multiple rows into a table using a <code>for</code> loop. What I require is for the same value (<code>$id</code>) to be inserted into all rows of the "id" column. Likewise, the timestamp should be inserted into the "submitted" column over all iterations.</p>
  
  <p>My current code only inserts one column. Here is the code:</p>
  
  <pre><code> if($stmt = $link-&gt;prepare("INSERT INTO table (id, alt_ord, alt_id, rank, submitted) VALUES ($id,?,?,?, NOW())")){
        $stmt-&gt;bind_param('iii', $q_ord, $q_ID, $rating);
  
        for($i=0; $i &lt; count($_POST['alt_ord']); $i++){
             $q_ord = $_POST['alt_ord'][$i];
             $q_ID = $_POST['alt_id'][$i];
             $rating = $_POST['rank_'][$i];
             $stmt-&gt;execute();
        }
        $stmt-&gt;close();
   }
  </code></pre>
  
  <p>Using a combination of ?s with <code>$id</code> and <code>NOW()</code> in the <code>INSERT</code> statement is clearly incorrect. How would I repeat the ID and timestamp values in the insert as intended?</p>