douxie1894 2018-07-25 10:54
浏览 92
已采纳

使用php的HTML表单不能使用单个提交按钮。

I am developing a form in html and php and there are multiple section in a page and I want a single submit button for every section. But I am unable to do it. With multiple submit buttons it works. Can anybody help me out with this problem.I need to create a form with single submit button. Here is the example code..

    <html lang="en">
        <head>
        <meta charset="UTF-8">
        <title>Add Records Form</title>
        </head>
        <body>
        <table style="width:100%">
        <tr>
        <th rowspan="2">
        <div class="container">
            <div class="row">
            <div class="col-md-8 col-md-offset-2">
            <form action="insert1.php" method="post" enctype="multipart/form-data">
            <div class="form-group">
            <label class="control-label">NCBI Accession number</label>
            <input type="text" name="Gene_NCBI_Accession_number" placeholder="NCBI Accession number" class="form-control">
            </div>
            <div class="form-group">
            <label class="control-label">locus tag</label>
            <input type="text" name="Gene_name_locus_tag" placeholder="locus tag" class="form-control">
            </div>

            </th>

            <td>
            <div class="container">
            <div class="row">
            <div class="col-md-8 col-md-offset-2">
            <form action="insert1.php" method="post" enctype="multipart/form-data">
            <div class="form-group">
            <label class="control-label"><b>Antibiotic</label>
            <input type="text" name="Antibiotic_name" placeholder="Antibiotic name" class="form-control">
            </div>
            </td>
            <td>
            <div class="form-group">
            <label class="control-label"><b>Name</label>
            <input type="text" name="Name" placeholder="Name" class="form-control" required>
            </div>
            </td>
          </tr>
          <tr>
              <td rowspan="2">
        <h4> Please fill in information for other related data or give your comments if any</h4>
        <br>
        <textarea rows="7" cols="100" name="comment" form="usrform">
        Enter text here...</textarea>

              </td>
              <td>
                  </div>
                                         <div class="form-group">
                                <label class="control-label"><b>Protein function</label>
                                <input type="text" name="Protein_function" placeholder="Protein_function" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label">Biological process</label>
                                <input type="text" name="Biological_process" placeholder="Biological process" class="form-control">
                            </div>

              </td>

          </tr><br>
            <br>
            <br>
            <br>
            <br>
            <br>
                 </form></table>
             <input type="submit" value="Add Records">
        <?php include 'footer.php'; ?>
        </body>
        </html>      

        <?php
        /* Attempt MySQL server connection. Assuming you are running MySQL
        server with default setting (user 'root' with no password) */
        $link = mysqli_connect("abc", "abc", "abc", "abc");

        // Check connection
        if($link === false){
            die("ERROR: Could not connect. " . mysqli_connect_error());
        }

        // Escape user inputs for security
        $Gene_NCBI_Accession_number = mysqli_real_escape_string($link, $_REQUEST['Gene_NCBI_Accession_number']);
        $Gene_name_locus_tag = mysqli_real_escape_string($link, $_REQUEST['Gene_name_locus_tag']);
        $Antibiotic_name = mysqli_real_escape_string($link, $_REQUEST['Antibiotic_name']);
        $Name = mysqli_real_escape_string($link, $_REQUEST['Name']);
        $Protein_function = mysqli_real_escape_string($link, $_REQUEST['Protein_function']);
        $Biological_process= mysqli_real_escape_string($link, $_REQUEST['Biological_process']);


        // attempt insert query execution
        $sql = "INSERT INTO contact_form_info (Gene_NCBI_Accession_number, Gene_name_locus_tag, Antibiotic_name, Name, Protein_function, Biological_process) VALUES ('$Gene_NCBI_Accession_number', '$Gene_name_locus_tag', '$Antibiotic_name', '$Name','$Protein_function', '$Biological_process' )";
        if(mysqli_query($link, $sql)){
            #echo "Records added successfully.";
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
        }

        // close connection
        mysqli_close($link);
        ?>
  • 写回答

1条回答 默认 最新

  • doubaben7394 2018-07-25 11:00
    关注

    Your submit button is outside of form that's why its not working. Refer below code to resolve your issue.

    <html lang="en">
            <head>
            <meta charset="UTF-8">
            <title>Add Records Form</title>
            </head>
            <body>
            <table style="width:100%">
            <tr>
            <th rowspan="2">
            <div class="container">
                <div class="row">
                <div class="col-md-8 col-md-offset-2">
                <form action="insert1.php" method="post" enctype="multipart/form-data">
                <div class="form-group">
                <label class="control-label">NCBI Accession number</label>
                <input type="text" name="Gene_NCBI_Accession_number" placeholder="NCBI Accession number" class="form-control">
                </div>
                <div class="form-group">
                <label class="control-label">locus tag</label>
                <input type="text" name="Gene_name_locus_tag" placeholder="locus tag" class="form-control">
                </div>
    
                </th>
    
                <td>
                <div class="container">
                <div class="row">
                <div class="col-md-8 col-md-offset-2">
                <form action="insert1.php" method="post" enctype="multipart/form-data">
                <div class="form-group">
                <label class="control-label"><b>Antibiotic</label>
                <input type="text" name="Antibiotic_name" placeholder="Antibiotic name" class="form-control">
                </div>
                </td>
                <td>
                <div class="form-group">
                <label class="control-label"><b>Name</label>
                <input type="text" name="Name" placeholder="Name" class="form-control" required>
                </div>
                </td>
              </tr>
              <tr>
                  <td rowspan="2">
            <h4> Please fill in information for other related data or give your comments if any</h4>
            <br>
            <textarea rows="7" cols="100" name="comment" form="usrform">
            Enter text here...</textarea>
    
                  </td>
                  <td>
                      </div>
                                             <div class="form-group">
                                    <label class="control-label"><b>Protein function</label>
                                    <input type="text" name="Protein_function" placeholder="Protein_function" class="form-control">
                                </div>
                                <div class="form-group">
                                    <label class="control-label">Biological process</label>
                                    <input type="text" name="Biological_process" placeholder="Biological process" class="form-control">
                                </div>
    
                  </td>
    
              </tr><br>
                <br>
                <br>
                <br>
                <br>
                <br><input type="submit" value="Add Records">
                     </form></table>
    
            <?php include 'footer.php'; ?>
            </body>
            </html>      
    
            <?php
            /* Attempt MySQL server connection. Assuming you are running MySQL
            server with default setting (user 'root' with no password) */
            $link = mysqli_connect("abc", "abc", "abc", "abc");
    
            // Check connection
            if($link === false){
                die("ERROR: Could not connect. " . mysqli_connect_error());
            }
    
            // Escape user inputs for security
            $Gene_NCBI_Accession_number = mysqli_real_escape_string($link, $_REQUEST['Gene_NCBI_Accession_number']);
            $Gene_name_locus_tag = mysqli_real_escape_string($link, $_REQUEST['Gene_name_locus_tag']);
            $Antibiotic_name = mysqli_real_escape_string($link, $_REQUEST['Antibiotic_name']);
            $Name = mysqli_real_escape_string($link, $_REQUEST['Name']);
            $Protein_function = mysqli_real_escape_string($link, $_REQUEST['Protein_function']);
            $Biological_process= mysqli_real_escape_string($link, $_REQUEST['Biological_process']);
    
    
            // attempt insert query execution
            $sql = "INSERT INTO contact_form_info (Gene_NCBI_Accession_number, Gene_name_locus_tag, Antibiotic_name, Name, Protein_function, Biological_process) VALUES ('$Gene_NCBI_Accession_number', '$Gene_name_locus_tag', '$Antibiotic_name', '$Name','$Protein_function', '$Biological_process' )";
            if(mysqli_query($link, $sql)){
                #echo "Records added successfully.";
            } else{
                echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
            }
    
            // close connection
            mysqli_close($link);
            ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助