douxie1894
2018-07-25 10:54 阅读 76
已采纳

使用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 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);
            ?>
    
    点赞 评论 复制链接分享

相关推荐