0

Hello Guys,

I dont know how to do these, i have a existing code from the internet and use it and Successful Ok. But i dont kow how to save this to database. can you please help me guys? thanks in advance this is my code

<link rel="stylesheet" href="../css/bootstrap-3.1.1.min.css" type="text/css" />
<link rel="stylesheet" href="../css/bootstrap-multiselect.css" type="text/css" />
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
 <script type="text/javascript" src="../js/bootstrap-2.3.2.min.js"></script>
 <script type="text/javascript" src="../js/bootstrap-multiselect.js"></script>
<form id="form1" class="clearfix" method="POST" action="sendannouncement.php">
  <fieldset>
    <legend>Post Announcement</legend>
    <br>
    <label>Subject</label>
    <div class="input-control text size8" data-role="input-control">
        <input type="text" name="subject" required placeholder="Subject">
        <button class="btn-clear" tabindex="-1"></button>
    </div>
    <label>Recipients</label>
        <select id="chkveg" multiple="multiple" name="recipients" required>
    <?php
      $acdemployee = new Acdemployee;
      $acdemployees = $acdemployee->fetch_all();
      foreach($acdemployees as $acdemployee) { ?>
        <option value="<?php echo $acdemployee['empid']; ?>"><?php echo $acdemployee['fname']; ?></option>
      <?php } ?>
                  </select><br /><br />
                    <script type="text/javascript">
                        $(function() {
                            $('#chkveg').multiselect({
                                includeSelectAllOption: true
                            });
                            $('#btnget').click(function() {

                            })
                        });
      </script>
      <script type="text/javascript">
          $(document).ready(function() {
          $('#chkveg').multiselect();
          });
</script>

    <label>Message</label>
    <div class="input-control textarea size8">
        <textarea name="msg">Type Here</textarea>
    </div>
    <br>
    <button class="primary" name="send">Send</button>
  </fieldset>
</form>

and this is my code for saving to database

<?php
 include_once('../include/connection.php');
if(isset($_POST['send'])){

    $empid = $_POST['recipient'];
    $msgdate = date("m/d/Y");
    $sender = "Administrator";
    $msg = $_POST['msg'];
    $subject = $_POST['subject'];

    $sql = "INSERT INTO empinbox (empid,msgdate,sender,msg,subject) VALUES (:empid,:msgdate,:sender,:msg,:subject)";
    $q = $pdo->prepare($sql);
    $q->execute(array(':empid'=>$empid, ':msgdate'=>$msgdate,':sender'=>$sender, ':msg'=>$msg,':subject'=>$subject,));
    header('location:postannounce.php');
}

?>a

thanks in advance guys.

2
Contributors
1
Reply
6
Views
2 Years
Discussion Span
Last Post by Taywin
0

Errr... This is why copy-and-paste is not teaching one to learn... If you are asking people here to give you the code, then I have to decline. If you ask us to guide you how to do it, I would say you need to read on how to pass variable from one page to the other, and then VERIFY that all user input are valid BEFORE insert into your database. Your PHP file to handle this should also be named the same as whatever action your form is sending to.

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.