php – How to update only one column in MySQL database with value from multiple select-ThrowExceptions

Exception or error:

I have this table that look similar like this:-

enter image description here

In HTML page, I make one multiple select control and include all the values.

I don’t know how to carry the value from HTML page to the .php page and process the update SQL there. I’ve tried search but only found on this and I tried but failed.

This is what I have tried.

HTML PAGE

<table border="1" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td>
        <select name="condition1a[]" multiple>
          <option value="Dent">D</option>
          <option value="Paint">P</option>
          <option value="Scratch">S</option>
        </select><br>
      </td>
      <td>
        <select name="condition1b[]" multiple>
          <option value="Dent">D</option>
          <option value="Paint">P</option>
          <option value="Scratch">S</option>
        </select><br>
      </td>
      <td>
        <select name="condition1c[]" multiple>
          <option value="Dent">D</option>
          <option value="Paint">P</option>
          <option value="Scratch">S</option>
        </select><br>
      </td>
    </tr>
  </tbody>
</table>

PHP PAGE

<?php
    if(isset($_POST['submitcondition']))
    {
       $c1a = $_POST['condition1a'];
       mysql_query("UPDATE rentalscf SET cf_1213='".join("'|##|'",$c1a)."'
                    WHERE rentalsid = '".$jobsid."';");

       $c1b = $_POST['condition1b'];
       mysql_query("UPDATE rentalscf SET cf_1215='".join("'|##|'",$c1b)."'
                    WHERE rentalsid = '".$jobsid."';");

       $c1c = $_POST['condition1c'];
       mysql_query("UPDATE rentalscf SET cf_1217='".join("'|##|'",$c1c)."'
                    WHERE rentalsid = '".$jobsid."';");

       $c1d = $_POST['condition1d'];
       mysql_query("UPDATE rentalscf SET cf_1219='".join("'|##|'",$c1d)."'
                    WHERE rentalsid = '".$jobsid."';");
    }
 ?>

I can display the condition when echo the condition array but cannot update in DB. Probably something wrong with my syntax or logic?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *