doulu8847 2014-12-15 11:14
浏览 28

每个文件中的代码都在工作,但在每个表中记录条目重复两次

Validation process is correct and data entries are also happening but records are inserted two times in each table at an instant of form submission.

**library.php HTML CODE**

        <form id="book_entry_form">
          <table class="table borderless table-condensed">                  
            <tr>
              <td><label for="entry_isbn">ISBN No.:</label></td>
              <td><input type="text" id="entry_isbn" class="form-control input-sm eqtxt" name="entry_isbn"></td>
            </tr>
            <tr>
              <td><label for="entry_subject">Subject:</label></td>
              <td><input type="text" id="entry_subject" class="form-control input-sm eqtxt" name="entry_subject"></td>
            </tr>

            <tr>
              <td></td>
              <td>
                <button id="entry_sub_btn" type="submit" class="btn btn-primary logbtn">Submit</button>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <button href="#" type="reset" class="btn btn-primary logbtn">Refresh</button>
              </td>
            </tr> 
          </table><!-- table closed -->    
        </form><!-- form -->

lib_book_reg.js Javascript code

$('#book_entry_form').bootstrapValidator({
                group: 'td',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    entry_isbn: {
                        message: 'The ISBN NO. is not valid',
                        validators: {
                            notEmpty: {
                                message: 'ISBN No. is required and cannot be empty'
                            }
                        }
                    },            

                    entry_subject: {
                       message: 'The subject name is not valid',
                        validators: {
                            notEmpty: {
                                message: 'Subject name is required and cannot be empty'
                            }
                        }
                    }             
                }
            })


        .on('success.field.bv', function(e, data) {
                    if (data.bv.isValid()) {
                        data.bv.disableSubmitButtons(false);
                        $('#entry_sub_btn').on('click',function(e){

            e.preventDefault();
            e.stopPropagation();


           var entry_isbn = $('#entry_isbn').val();
           var entry_subject= $('#entry_subject').val();

           $.ajax({
              url: 'php/lib_book_reg.php',
              type: 'post',
              data: { 'entry_isbn':entry_isbn, 'entry_subject':entry_subject },
              success: function(data) {
                alert(data);
                window.location.reload(true);

              },
              cache: false
            }); // end ajax call
         }); // end of button click event
         } //end of if statement
         }); // end of main function

lib_book_reg.php PHP CODE

<?php
    session_start();
    if($_SESSION['user'] != "Library")
    {
        echo "Only Librarian is authorized to make an entry!";
    exit();
    }
    require 'config.php';

    // $eid = $_POST['eid'];
    $entry_isbn = $_POST['entry_isbn'];
    $entry_subject = $_POST['entry_subject'];


    $stmt = $dbh->prepare("INSERT INTO lib_book_reg(l_book_isbn, l_book_subject)    VALUES(?,?)");
    $stmt->execute(array($entry_isbn, $entry_subject));

    $stmt1 = $dbh->prepare("INSERT INTO l_book_opr_db(l_book_isbn, l_book_subject)  VALUES(?,?)");
    $stmt1->execute(array($entry_isbn, $entry_subject));

    echo "Registered Successfully";
    ?>
  • 写回答

1条回答 默认 最新

  • doufu2496 2014-12-15 12:52
    关注

    try disabling the button after the click event. try adding (you can enable it after a timeout or after the ajax is success)

    $(this).attr('disabled',true);
    

    after

    $('#entry_sub_btn').on('click',function(e){
    

    UPDATE

    This can also be because the click event is assigned twice for that button.

    so before assigning, just unbind the old click event and assign new.

    sample code

    $('#entry_sub_btn').off('click').on('click',function(e){
    
    评论

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?