I am currently working on a mailing/messaging system. Now I want to send a message, but I want to add more recipients, but I can’t do this. It would be kind if one of you would like to help me.
I would like each message(body, from and subject) to be in a separate table. And that the message id and to(and if there are multiple recipients that it creates multiple rows.) come in another table.
(My English is not so good, so sorry if there are spelling mistakes).
// JS for the to-tags.
function parse() {
var tag_input = document.getElementById("tags_input");
var tags = document.getElementById("tags");
//
var input_val = tag_input.value.trim();
var no_comma_val = input_val.replace(/,/g, "");
//
if (input_val.slice(-1) === "," && no_comma_val.length > 0) {
var new_tag = compile_tag(no_comma_val);
tags.appendChild(new_tag);
tag_input.value = "";
}
}
function compile_tag(tag_content) {
let a = -3;
var tag = document.createElement("p");
//
var text = document.createElement("span");
text.setAttribute("class", "badge badge-success");
text.setAttribute("id", tag_content);
text.innerHTML = tag_content;
//
var remove = document.createElement("i");
remove.setAttribute("class", "fa fa-remove");
remove.setAttribute("id", "remove");
remove.onclick = function() {this.parentNode.remove();};
//
tag.appendChild(remove);
tag.appendChild(text);
//
return tag;
}
// HTML AND PHP
<?php
session_start();
include_once("error.php");
include "db.php";
if (isset($_SESSION['login'])){
?>
<?php
$functions = array('newMessage');
if (isset($_GET['action'])){
if (in_array($_GET['action'], $functions)){
function newMessage(){
// when on the button press
if (isset($_POST['button_send'])) {
global $conn;
// take the user id
$from = $_SESSION['id'];
// create table one
$create = "INSERT INTO `messages` SET
`messageFrom` = '$from',
`messageSubject` = '".mysqli_real_escape_string($conn, $_POST['inp_subject'])."',
`messageBody` = '".mysqli_real_escape_string($conn, $_POST['textarea_body'])."'
";
// when table one is created make table to. **This is where things go wrong**
if (mysqli_query($conn, $create)){
if ($create = true){
$read = mysqli_query($conn, "SELECT * FROM `blog` WHERE `messageSubject` = '$_POST['inp_subject']' AND `messageFrom` = '$from' ");
$data = mysqli_fetch_assoc($read);
$id = $data['messageId'];
$create = "INSERT INTO `receivers` SET
`messageId` = '$id',
`messageSubject` = '".mysqli_real_escape_string($conn, $_POST['inp_subject'])."',
`messageBody` = '".mysqli_real_escape_string($conn, $_POST['textarea_body'])."'
"; if (mysqli_query($conn, $create)){
echo "fine";
}else{
echo 'Sorry, '.mysqli_error($conn);
}
}else{
echo 'Sorry, '.mysqli_error($conn);
}
}else{
echo 'Sorry, '.mysqli_error($conn);
}
}
?>
<form method="post">
<div class="from_group">
<input type="text" name="inp_to" id="inp_to" placeholder="Give the name(s)..." required>
<label>To:</label>
</div>
// The TO-input
<div class="container">
<div class="col-sm-6">
<input onkeyup="parse();" type="text" id="tags_input" placeholder="comma-separated tags" maxlength="100" class="form-control">
</div>
// the to tags
<div class="col-sm-6" id="tags" name="tags">
</div>
</div>
<script src="js/input_comma.js"></script>
<div class="from_group">
<input type="text" placeholder="Give the subject..." name="inp_subject" required>
<label>Subject: </label>
</div>
<div class="from_group">
<textarea name="textarea_body" rows="10" cols="30">
</textarea>
</div>
<button name="button_send"> Send </button>
</form>
</div>
<?php
}
echo $_GET['action'] ();
}else{
functionNotfound();
}
}
?>
<?php
}else{
notLoggedin();
}
?>
Already thanks for the help.
I would like each message(body, from and subject) to be in a separate table. And that the message id and to(and if there are multiple recipients that it creates multiple rows.) come in another table.