lundi 26 juin 2017

Insert Multiple Names, E-Mails or Text Messages Checkbox Values into a Database

I have looked throughout stackoverflow for the right solution to my particular problem, but because I not proficient in php I'm not able to figure this one out.

I have a form that list multiple users that have registered for a class. There are two groups for the sessioner's class. They are student attendees and sessioner attendees.

In this form, the sessioner can send an email or text message to one registrant or to all of the registrants from either group using the myCheckboxes[ ]. I have no problem emailing the email(s) or texting the text message(s) and inserting the online form's values into the database (I know I need to be using MySQLi) and thus, creating a row (id) for each myCheckboxes[ ].

The problem I have is not being able to insert the student attendee's or the sessioner attendee's name, email or text-number into the database fields toname, toemail or totext for each myCheckboxes[ ]. I don't know how to write the $_Post or the mysql insert to do this. Any help would be greatly appreciated.

Send E-Mail or Text Message Code

if ($_POST) {
$emails = array();
$count = 0;

$emails = $_POST['myCheckboxes'];

$fromname = $_POST['fromname'];
$fromemail = $_POST['fromemail'];
$tocc = $_POST['tocc'];
$emailsubject = $_POST['emailsubject'];
$yourmessage = $_POST['yourmessage'];

$sender_email = $fromemail; //sender email
$subject = $emailsubject; //subject of email
$message = $yourmessage; //message body

if ($_FILES['my_file']['name']) {
    //get file details we need
    $file_tmp_name = $_FILES['my_file']['tmp_name'];
    $file_name = $_FILES['my_file']['name'];
    $file_size = $_FILES['my_file']['size'];
    $file_type = $_FILES['my_file']['type'];
    $file_error = $_FILES['my_file']['error'];

    if ($file_error > 0) {
        die('upload error');
    }
    //read from the uploaded file & base64_encode content for the mail
    $handle = fopen($file_tmp_name, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $encoded_content = chunk_split(base64_encode($content));

    $file_status = 1;
}

foreach ($emails as $email) {

    $boundary = md5("sanwebe");
    //header
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "From:" . $sender_email . "\r\n";

    $headers .= "CC: " . $tocc . "\r\n";
    $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";

    //plain text
    $body = "--$boundary\r\n";
    $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
    $body .= "Content-Transfer-Encoding: base64\r\n\r\n";
    $body .= chunk_split(base64_encode($message));

    if ($file_status == 1) {
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: " . rand(1000, 99999) . "\r\n\r\n";
$body .= $encoded_content;
    }

    //$sentMail = @mail($email, $subject, $body, $headers);
    //mail($email, $subject, $body, $headers);

$qr=mysql_query("insert into view_reg_users (timestamp,fromname,fromemail,tocc,emailsubject,my_file,yourmessage) values ('".$timestamp."','".$fromname."','".$fromemail."','".$tocc."','".$emailsubject."','".$my_file."','".$yourmessage."')");

    if (!mail($email, $subject, $body, $headers))
    echo "<script>window.alert('Email cannot be sent to" . $email . "')</script>";
    else $count++;
}}

Student Attendee(s) Send E-Mail or Text Message Code

<td width="50%">
    <strong><center><input type="checkbox" name="myCheckboxes[]" id="student_name" class="all_studentemails" value="<?php echo $student_Name; ?>" />&nbsp;Full Name
    <input type="checkbox" name="myCheckboxes[]" id="student_emails" class="all_studentemails" value="<?php echo $student_Email; ?>" />&nbsp;E-Mail Address</center></strong>
</td>
<td width="50%">
    <strong><center><input type="checkbox" name="myCheckboxes[]" class="all_studenttexts" id="student_texts" value="<?php echo $student_Contact; ?>" />&nbsp;
    Text Messaging</center></strong>
</td>

Sessioner Attendee(s) Send E-Mail or Text Message Code

<td width="50%">
    <strong><center><input type="checkbox" name="myCheckboxes[]" id="sessioner_name" class="all_sessioneremails" value="<?php echo $sessioner_Name; ?>" />&nbsp;
    Full Name<input type="checkbox" name="myCheckboxes[]" id="sessioner_emails" class="all_sessioneremails" value="<?php echo $sessioner_Email; ?>" />&nbsp;
    E-Mail Address</center></strong>
</td>
<td width="50%">
    <strong><center><input type="checkbox" name="myCheckboxes[]" id="sessioner_texts" class="all_sessionertexts" value="<?php echo $sessioner_Contact; ?>" />&nbsp;
    Text Messaging</center></strong>
</td>

Online Form Link

Online Form Image

Database Link

Database Image




Aucun commentaire:

Enregistrer un commentaire