title: Insert details of a form in to MySQL Table based on number of selected options
body: <p>I have a form by which i use to send mails to users.</p>
  
  <pre><code>&lt;form method="post" action="/functions/mails/mailstomysql.php"&gt;
  &lt;?php
  $sql="SELECT UserId, FatherName, FirstName FROM profiles"; 
  
  echo "&lt;div class='FieldTitle' style='display:none;'&gt;To&lt;/div&gt;";
  echo "
  &lt;div class='ui segment'&gt;
    &lt;div class='ui fluid multiple search selection dropdown'&gt;
      &lt;input type='hidden' multiple name='ReceiverId[]' required&gt;
      &lt;i class='dropdown icon'&gt;&lt;/i&gt;
      &lt;input class='search' tabindex='0'&gt;
      &lt;div class='default text'&gt;To&lt;/div&gt;
      &lt;div class='menu' tabindex='-1'&gt;
  
      "; // list box select command
  foreach ($conn-&gt;query($sql) as $row){//Array or records stored in $row
  
  echo "
  &lt;option class='item' data-value='".$row['UserId']."' value='".$row['UserId']."'&gt;$row[FirstName] s/o $row[FatherName]&lt;/option&gt;"; 
  
  }
   echo "
  &lt;/div&gt;
  &lt;/div&gt; 
  &lt;/div&gt;
  ?&gt;
  
      &lt;input type="text" name="MailSubject"&gt;
  
      &lt;textarea type="text" name="MailContent"&gt;&lt;/textarea&gt;
  
      &lt;input id="btnAddRecord" name="submit" type="submit" value="Send"&gt;  
  
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the SQL Statement that retrieve the data for above form:</p>
  
  <pre><code>$sql="SELECT UserId, FirstName FROM profiles"; 
  </code></pre>
  
  <p>And this is the <code>mailtomysql.php</code> file which insert the data into MySQL database.</p>
  
  <pre><code>$ReceiverId=$_POST['ReceiverId'];
  $MailSubject=$_POST['MailSubject'];
  $MailContent=$_POST['MailContent'];
  
  $sql = "INSERT INTO mails (
  `ReceiverId`, `MailSubject`, `MailContent`, `MailRead`, `MailDate`
  )
  VALUES (
  '$ReceiverId', '$MailSubject', '$MailContent', '1', CURRENT_TIMESTAMP()
  )";
  
  if ($conn-&gt;query($sql) === TRUE) {
  echo "Mail sent!";
  } else {
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  </code></pre>
  
  <p>The above code works awesome and perfect.</p>
  
  <p><strong>My Question</strong></p>
  
  <p>The above <code>mailtomysql.php</code> file insert the selected users from <code>Multiple Selection Box</code> and post the selected user ids to <code>ReceiverId</code> column which i do not want that, instead i want to have row for every selected user.</p>
  
  <p>like:</p>
  
  <p><strong>Now</strong></p>
  
  <p><em>ReceverId</em></p>
  
  <hr>
  
  <p>114, 265, 112</p>
  
  <hr>
  
  <p><strong>What i want</strong></p>
  
  <p><em>ReceverId</em></p>
  
  <hr>
  
  <p>114</p>
  
  <hr>
  
  <p>256</p>
  
  <hr>
  
  <p>112</p>
  
  <hr>
  
  <p><strong>Why</strong></p>
  
  <p>If a user want to delete the mail then it will delete the mail and other users which are in that mail will not see the mail too because it is deleted by a user.</p>
  
  <p>So once more my question is how to make <code>mailtomysql.php</code> file to make row for every selected users rather than having selected users ids in one row.</p>
  
  <p><strong>Edited:</strong>
  I used the <a href="http://semantic-ui.com/modules/dropdown.html#multiple-search-selection" rel="nofollow noreferrer">Semantic-Ui</a> to select the options from the dropdown list, but it is not working.</p>