Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有php的HTML表单不能使用单个提交按钮。_Php_Mysql_Html - Fatal编程技术网

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

带有php的HTML表单不能使用单个提交按钮。,php,mysql,html,Php,Mysql,Html,我正在用html和php开发一个表单,页面中有多个部分,我希望每个部分都有一个提交按钮。但是我做不到。通过多个提交按钮,它可以工作。有人能帮我解决这个问题吗?我需要用一个提交按钮创建一个表单。下面是示例代码 <html lang="en"> <head> <meta charset="UTF-8"> <title>Add Records Form</title> &

我正在用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);
        ?>

添加记录表单
NCBI登录号
位点标签
抗生素
名称
其他相关资料请填写,如有意见请提出

在此处输入文本。。。 蛋白质功能 生物过程






你的提交按钮在表单之外,这就是为什么它不起作用。请参阅下面的代码以解决您的问题

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

添加记录表单
NCBI登录号
位点标签
抗生素
名称
其他相关资料请填写,如有意见请提出

在此处输入文本。。。 蛋白质功能 生物过程






您的提交输入在formIn HTML之外,您不能让一个表单位于另一个表单内。只需包含一个表单,并且在该表单中有多个提交按钮。@lessan这在使用
form=
属性“您的提交按钮在表单之外”时不是问题。。。并且缺少
表单
属性。在HTML5中,元素被允许在表单之外。欢迎使用……别忘了接受它作为正确答案。快乐编码:)