mercredi 31 janvier 2018

Changing database boolean using html checkboxes

I want to change the value of my database 'Sent' boolean to true when the user clicks a checkbox.

My contact.php so I can edit what I want the message and the subject to be in my website

<?php
    if(isset($_POST['submit'])){
      $to = $_POST['email'];
      $from = "my_email@gmail.com";
      $subject = $_POST['subject'];
      $message = $_POST['message'];

      $headers = "From:" . $from;
      mail($to,$subject,$message,$headers);
      echo "Email sent!";
      }
?>

My index.php, dbh has the connection while the contact.php has the php so I can send emails to several recipients:

<?php
    include_once 'dbh.php';  
    include_once 'contact.php';  
?>

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

</head>

<body>

    <div class="container">
    <br>
    <div class="row justify-content-center">
    <br>
    <table class="scroll">
    <thead>

        <tr>
            <th>Schools Name</th>
           <th>Schools Email</th>
           <th>Sent</th>
        </tr>

    </thead>

    <tbody>
        <?php

            $execItems = $conn->query("SELECT Name,SchoolMail,Sent FROM Schools");

            while($infoItems = $execItems->fetch_array()){
                echo    "
                        <tr>
                            <td>".$infoItems['Name']."</td>
                            <td>".$infoItems['SchoolMail']."</td>
                            <td>".$infoItems['Sent']."</td>
                        </tr>
                    ";

            }
        ?>
    </tbody>
</table>


            <div class="mail">
            <form action="" method="post">
            <button type="button" onclick="emailNext();">Add Email</button>
            <div id="addEmail"></div>

            <script>

            function emailNext() {
            var nextEmail, inside_where;
            nextEmail = document.createElement('input');
            nextEmail.type = 'text';
            nextEmail.name = 'email[]';
            nextEmail.className = 'class_for_styling';
            nextEmail.style.display = 'block';
            nextEmail.placeholder = 'Inserrt your Email';
            inside_where = document.getElementById('addEmail');
            inside_where.appendChild(nextEmail);
            return false;
            }

            </script>

            Subject:<br><textarea rows="1" name="subject" cols="30"></textarea><br>
            Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
            <input type="submit" name="submit" value="Submit">
            </form>
                </form>
            </div>
        </div>
    </div>
</body>

</html>

Is there a way so when a user clicks on a checkbox it sends data to the database and changes its value to true, so the checkbox stays active.




Aucun commentaire:

Enregistrer un commentaire