javascript - Can't add subject to the database -


i creating php pahe have slist of subject have button add new subject. when click add subject modal appear , input data data inputted not added

this mymodal

<div class="modal fade" id="add_new_record_modal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel"> <div class="modal-dialog" role="document">     <div class="modal-content">         <div class="modal-header">             <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span></button>             <h4 class="modal-title" id="mymodallabel">add new record</h4>         </div>         <div class="modal-body">              <div class="form-group">                 <label for="subjcode">subject code</label>                 <input type="text" id="subjcode" placeholder="subject code" class="form-control"/>             </div>              <div class="form-group">                 <label for="subjname">subject name</label>                 <input type="text" id="subjname" placeholder="subject name" class="form-control"/>             </div>              <div class="form-group">                 <label for="proctor">proctor</label>                 <input type="text" id="proctor" placeholder="proctor" class="form-control"/>             </div>           </div>         <div class="modal-footer">             <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button>             <button type="button" class="btn btn-primary" onclick="addrecord()" >add subject</button>         </div>     </div> </div> </div> 

this js code adding subject

  // add record function addrecord() { // values var subjcode = $("#subjcode").val(); var subjname = $("#subjname").val(); var proctor = $("#proctor").val();  // add record $.post("project/ajax/addrecord.php", {     subjcode: subjcode,     subjname: subjname,     proctor: proctor }, function (data, status) {     // close popup     $("#add_new_record_modal").modal("hide");      // read records again     readrecords();      // clear fields popup     $("#subjcode").val("");     $("#subjname").val("");     $("#proctor").val(""); });  }            // read records       function readrecords() {    $.get("ajax/readrecords.php", {}, function (data, status) {        $(".records_content").html(data);   });     } 

and addrecord.php

<?php if(isset($_post['subjcode']) && isset($_post['subjname']) && isset($_post['proctor'])) {     // include database connection file     include("connect.php");      // values     $subjcode = $_post['subjcode'];     $subjname = $_post['subjname'];     $proctor = $_post['proctor'];      $query = "insert subject(subjcode, subjectname, proctor) values('$subjcode', '$subjname', '$proctor')";     if (!$result = mysqli_query($dbcon, $query)) {         exit(mysqli_connect_error($dbcon));     }     echo "1 subject added!"; }     else {echo "failed add";}?> 

readrecords.php

<?php // include database connection file include("connect.php");  // design initial table header  $query = "select * subject";  if (!$result = mysqli_query($dbcon, $query)) {     exit(mysqli_connect_error($dbcon)); }  // if query results contains rows featch rows if(mysqli_num_rows($result) > 0) {     $number = 1;     while($row = mysqli_fetch_assoc($result))     {         $data = "<br><br><br><center><button class='btn btn-success' onclick='section()'>".$row['subjcode']."</button><button class='btn btn-success' data-toggle='modal' data-target='#add_new_record_modal'>add subject</button></center>";         $number++;     } }   echo $data; ?> 

my question why cant add inputted data in database?


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -