簡體   English   中英

如何在單擊提交按鈕時顯示隱藏表,並在php中的數據庫表中插入數據?

[英]how to display a hidden table when submit button is clicked and data is inserted in database table in php?

我有一個從中輸入項目名稱和工作表名稱,它將保存在項目表中。 基於此,我在另一個表'Data'上插入空值。 我正在使用可編輯的表來更新數據庫中的這些空值。 我希望隱藏此表,直到提交項目名稱和工作表名稱,並且一旦提交了值,則只顯示表格。 我已經嘗試了很多但是在點擊提交按鈕后,我的表格會一直顯示,直到頁面重新加載,並且在加載完成后會顯示消息。 我的代碼部分如下所示。

    <script>
     $(function(){
     $('button#showit').on('click',function(){  
    $('#myform').show();
     });
     });
    </script>
    <form class="form-horizontal" action="db.php" id="#form1" 
     onSubmit="function();" method="post">

    <input type="text" class="form-control1" name="projectname" 
   id="projectname" required >
    <input type="text" class="form-control1" name="sheetname" id="sheetname" 
    required >
    <button type="submit" name="submit" id="button" class="btn-
     success btn" >Submit</button>
        </form>
      <div class="tab-content"  id="myform" style="display:none">
     <div class="tab-pane active" id="horizontal-form">
     <?php 

       $s4 = "SELECT * FROM data ORDER BY data_id DESC LIMIT 1";
     $res = mysqli_query($bd, $s4);
    while ($row = mysqli_fetch_array($res))
                                 {
                            ?>  
   <table class="table table-bordered" style="width:50%;">
    <thead>
    <tr>
    <th>Sr.no</th>
    <th>Column Name</th>

       </tr>
     </thead>
     <tbody>

   <tr class="odd">
    <td>1</td>
     <td id="d1:<?php echo $row['data_id']; ?>" contenteditable="true"><?php 
    echo $row['d1']; ?></td>          
   </tr>

   .
   .
    .
   </tbody>
    </table>
   <?php } ?>
   </div>
   </div>
 on db.php I have used to get back on my previous page
    <script>
                    alert('Sheet Created Successfully');
                    window.location.href='index.php?success';

   </script>

我在你的代碼中無法幫助你,也許你應該重新調整一些東西,但是,這里有一些幫助:

$('#firstform').submit(function () {
//handle here a function to send data to db.php, then:
sendData();
$('#firstform').hide();
$('#hidedform').show();
     return false;
    });

如果您控制提交按鈕不刷新頁面,則可以隱藏第一個表單並顯示第二個表單。 如果你發布更多的代碼我會嘗試更清楚。

(“return false”使提交功能不刷新頁面)

這是另一篇關於不爽快的帖子......也許有幫助

 <!-- Example of jQuery Reference --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <!-- Your Hiding Script --> <script type='text/javascript'> $(document).ready(function(){ $("#AddNewRecord").hide(); }); </script> <!-- Your Markup --> <table border="1" cellpadding="2" id="AddNewRecord"> <tr style="width:25px;"> <td>Site</td> </tr> </table> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM