簡體   English   中英

帶有php的HTML表單不能與單個提交按鈕一起使用。

[英]HTML form with php is not working with a single submit button.

我正在用html和php開發表單,頁面中有多個部分,每個部分都需要一個提交按鈕。 但是我做不到。 使用多個提交按鈕,它可以工作。 任何人都可以幫我解決這個問題。我需要創建一個帶有單個提交按鈕的表單。 這是示例代碼。

    <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);
        ?>

您的提交按鈕不在表單之外,這就是為什么它不起作用的原因。 請參考下面的代碼來解決您的問題。

<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);
        ?>

暫無
暫無

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

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