I have a form by which i use to send mails to users.
<form method="post" action="/functions/mails/mailstomysql.php">
<?php
$sql="SELECT UserId, FatherName, FirstName FROM profiles";
echo "<div class='FieldTitle' style='display:none;'>To</div>";
echo "
<div class='ui segment'>
<div class='ui fluid multiple search selection dropdown'>
<input type='hidden' multiple name='ReceiverId[]' required>
<i class='dropdown icon'></i>
<input class='search' tabindex='0'>
<div class='default text'>To</div>
<div class='menu' tabindex='-1'>
"; // list box select command
foreach ($conn->query($sql) as $row){//Array or records stored in $row
echo "
<option class='item' data-value='".$row['UserId']."' value='".$row['UserId']."'>$row[FirstName] s/o $row[FatherName]</option>";
}
echo "
</div>
</div>
</div>
?>
<input type="text" name="MailSubject">
<textarea type="text" name="MailContent"></textarea>
<input id="btnAddRecord" name="submit" type="submit" value="Send">
</form>
This is the SQL Statement that retrieve the data for above form:
$sql="SELECT UserId, FirstName FROM profiles";
And this is the mailtomysql.php
file which insert the data into MySQL database.
$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->query($sql) === TRUE) {
echo "Mail sent!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
The above code works awesome and perfect.
My Question
The above mailtomysql.php
file insert the selected users from Multiple Selection Box
and post the selected user ids to ReceiverId
column which i do not want that, instead i want to have row for every selected user.
like:
Now
ReceverId
114, 265, 112
What i want
ReceverId
114
256
112
Why
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.
So once more my question is how to make mailtomysql.php
file to make row for every selected users rather than having selected users ids in one row.
Edited: I used the Semantic-Ui to select the options from the dropdown list, but it is not working.