title: Post array from HTML form, and use results to update multiple rows in a mysql table
body: <p>So I have this basic html form. My goal is to pass the values submitted to this form into a mysql table. </p>
  
  <pre><code> &lt;form action="?action=settings" method="post"&gt;
        &lt;ul&gt;
          &lt;li&gt;
             &lt;label for="settingValue[1]"&gt;Setting 1:&lt;/label&gt;
             &lt;input type="text" name="settingValue[1]" id="setting1" required /&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;label for="settingValue[2]"&gt;Setting 2:&lt;/label&gt;&lt;br&gt;
              &lt;input checked type="radio" name="settingValue[2]" value="1" /&gt;On&lt;br&gt;
              &lt;input type="radio" name="settingValue[2]" value="0" /&gt;Off
           &lt;/li&gt;
           &lt;li&gt;
               &lt;input type="submit" name="saveChanges" value="Save Changes" /&gt;
           &lt;/li&gt;
         &lt;/ul&gt;
     &lt;/form&gt;
  </code></pre>
  
  <p>My mysql table has only 3 columns (id, settingName, settingValue)
  So I want to update multiple records in my table using this form (In this case rows 1 and 2) by storing the value into the "settingValue" column.</p>
  
  <p>After some research I found that what seems to be the best way to do this would be by posting an array (Which is what I attempted to do above), then use a foreach loop to to run through the array and update the table.</p>
  
  <p>I guess my main problem is figuring out how to use the array.  Because I need to UPDATE a record NOT create a new one. I also need to retain the ID so I can update the corresponding record.</p>
  
  <p>After hours of googling my best guess was to do this:</p>
  
  <pre><code>if ( isset( $_POST['saveChanges'])) {
      foreach($_POST['settingValue'] as $key =&gt; $settingValue )  {
          $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
          $conn-&gt;exec("UPDATE settings SET settingValue=$settingValue WHERE id=$key");
          $conn = null;
      }
  </code></pre>
  
  <p>But it is yielding no results.</p>