简体   繁体   English

如何在单击提交按钮时显示隐藏表,并在php中的数据库表中插入数据?

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

I have one from through which I am entering project name and sheet name which will be saved in project table. 我有一个从中输入项目名称和工作表名称,它将保存在项目表中。 Based on this I am inserting empty values on another table 'Data'. 基于此,我在另一个表'Data'上插入空值。 I am using editable table to update these empty values in database. 我正在使用可编辑的表来更新数据库中的这些空值。 I want to hide this table till project name and sheet name is submitted and once value is submitted then only table will be displayed. 我希望隐藏此表,直到提交项目名称和工作表名称,并且一旦提交了值,则只显示表格。 I have tried a lot but after clicking submit button my table gets displayed till page is reloaded and disappers when loading is completed. 我已经尝试了很多但是在点击提交按钮后,我的表格会一直显示,直到页面重新加载,并且在加载完成后会显示消息。 My code parts are like below. 我的代码部分如下所示。

    <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>

I cant help you much in your code, maybe you should readjust some things, but, here´s some help: 我在你的代码中无法帮助你,也许你应该重新调整一些东西,但是,这里有一些帮助:

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

If you control the submit button not to refresh the page, you can hide first form and display second one. 如果您控制提交按钮不刷新页面,则可以隐藏第一个表单并显示第二个表单。 If you post more code I´ll try to be clearer. 如果你发布更多的代码我会尝试更清楚。

("return false" makes submit function not to refresh the page) (“return false”使提交功能不刷新页面)

here are another post about not refreshing...maybe it helps 这是另一篇关于不爽快的帖子......也许有帮助

 <!-- 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