简体   繁体   中英

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'. 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)

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM