0

These buttons are echo out from the database,

When the user clicks onto the button, the user will get to see a pop out before submitting it. enter image description here

This is my code,

    $con = getDbConnect();
    $day = date("l");

    if (mysqli_connect_errno($con)) {
        "Failed to connect to MySQL: " . mysqli_connect_error();
    } else {
        $result = mysqli_query($con, "SELECT * FROM timetableschedule WHERE day='" . $day . "'");

        while ($schedule = mysqli_fetch_array($result)) {
            ?>
  <div class="col-md-3">
    <button class="btn btn-warning" data-toggle="modal" data-target="#myModal" schedule="
    <?php
    echo "<br/>";
    echo $schedule['academicInstitution'] . "<br />";
    echo $schedule['startTime'] . "-" . $schedule['endTime'] .  "hrs<br />";
    echo "<br/>";
    ?>">
    <?php
    echo "<br/>";
    echo $schedule['academicInstitution'] . "<br />";
    echo $schedule['startTime'] . "-" . $schedule['endTime'] .  "hrs<br />";
    echo "<br/>";
    ?>
    </button>
  </div>
          <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Insert Today's Activity</h4>
            </div>

            <div class="modal-body">
                <p class="activity"></p>
                <p>Click on the submit button if the above infomation is correct.</p>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-primary btn-ok">Submit</a>
            </div>
        </div>
    </div>
</div>

<script>
    $('#myModal').on('show.bs.modal', function(e) {
        $(this).find('.btn-ok').attr('schedule', $(e.relatedTarget).attr('schedule'));

        $('.activity').html('You have selected: <strong>' + $(this).find('.btn-ok').attr('schedule') + '</strong>');
    });
</script>
  <?php
    }
    mysqli_close($con);
}
?>
</div>

Once the user click onto the submit button, the "academicInstitution" and "duration" will be entered into a database called, "myRecord".But I do not know how to connect the submit button to the database.

Raymond
  • 91
  • 2
  • 12
  • 1
    Assign `id="btn-submit"` to your _Submit_ button then use jQuery to send a POST request in this function `$("#btn-submit").click(function () { post request here });` – Sakamaki Izayoi Jul 25 '15 at 19:05

1 Answers1

0
  • If you need to stay on the same page, make an ajax post call to a server side php script: http://api.jquery.com/jquery.post/ This way you will be able to execute the query you want on the server
  • If you can accept to reload the page, you may simply use an html form

This question may be useful for you: jQuery Ajax POST example with PHP

Note that you don't necessarily need the form element if you choose the ajax post approach

Community
  • 1
  • 1
MazzCris
  • 1,812
  • 1
  • 14
  • 20