Monday, 24 September 2018

SQL Update entrys in multiple Tables after select from populated dropdown menu

need some help. I want to edit entrys via HTML/PHP Form in the primary key table i'll inserted in a previous page from 2 dropdown menu who has populated entrys from 2 foreign tables(microsoft sql server). The entrys are sended via $_Get Method. Here the example Tables: First the main table i want to update for example entry with PK_ID 1 change to TID 2 and Assign_ID 2 when i submit on the edit page.

+-------+-----+-----------+
| PK_ID | TID | Assign_ID |  
+-------+-----+-----------+
|     1 |   1 |         1 | 
|     2 |   2 |         2 | 
|     3 |   3 |         3 | 
+-------+-----+-----------+

Now the 2 Foreign Key Tables:

+-------+------------+
| TID   | technology |
+-------+------------+
|     1 | bla        |
|     2 | bli        |
|     3 | blubb      |
+-------+------------+

+----------+------------+
| Assign_ID| assignment |
+----------+------------+
|     1    | assign1    |
|     2    | assign2    |
|     3    | assign3    |
+----------+------------+

Here is my HTML/PHP Form with the old entrys which i want to update:

<tr class="wmfg_a">
 <td>
  <label class="wmfg_label_a" for="chk_technology">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;technology&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
  </td>
 <td>
  <select name="TID" size="1">
  <option><?php echo $_GET['technology'] ?> </option>;                 
  <?php
    foreach($result2 as $m)
     {
      echo "<option value=\"" . $m['TID'] . "\">" .$m['technology']"</option>";
     }
  ?>
  </select>
 </td>
</tr>

<tr class="wmfg_a">
 <td>
  <label class="wmfg_label_a" for="chk_assignment">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assignment&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  </label>
 </td>
 <td>
  <select id="neuIa" name="Assign_ID" size="1">
  <option><?php echo $_GET['assignment'] ?> </option>;
   <?php
    foreach($result3 as $m)
     {
      echo "<option value=\"" . $m['Assign_ID'] . "\">" .$m['assignment'] . "</option>";
     }
    ?><
  </select>
 </td>
</tr>

Here comes the SQl Code Where i have problems, because i select the names but i have to change the IDs in the main table.

$TID = $_POST['TID'];
$Assign_ID = $_POST['Assign_ID'];
$PK_ID = $_POST['PK_ID'];

$sql = "UPDATE Master.dbo.PK_Table SET TID='".$TID."', Assign_ID='". $Assign_ID."' WHERE Master.dbo.PK_Table.PK_ID =  '".$PK_ID."'";

Thx for your help :)



from SQL Update entrys in multiple Tables after select from populated dropdown menu

No comments:

Post a Comment