<legend id='SFcCo'><style id='SFcCo'><dir id='SFcCo'><q id='SFcCo'></q></dir></style></legend>
<i id='SFcCo'><tr id='SFcCo'><dt id='SFcCo'><q id='SFcCo'><span id='SFcCo'><b id='SFcCo'><form id='SFcCo'><ins id='SFcCo'></ins><ul id='SFcCo'></ul><sub id='SFcCo'></sub></form><legend id='SFcCo'></legend><bdo id='SFcCo'><pre id='SFcCo'><center id='SFcCo'></center></pre></bdo></b><th id='SFcCo'></th></span></q></dt></tr></i><div id='SFcCo'><tfoot id='SFcCo'></tfoot><dl id='SFcCo'><fieldset id='SFcCo'></fieldset></dl></div>

      <tfoot id='SFcCo'></tfoot>

      • <bdo id='SFcCo'></bdo><ul id='SFcCo'></ul>

      <small id='SFcCo'></small><noframes id='SFcCo'>

      1. PHP 多输入搜索

        时间:2023-09-24

            <bdo id='kMkph'></bdo><ul id='kMkph'></ul>
            <legend id='kMkph'><style id='kMkph'><dir id='kMkph'><q id='kMkph'></q></dir></style></legend>
          • <small id='kMkph'></small><noframes id='kMkph'>

            <i id='kMkph'><tr id='kMkph'><dt id='kMkph'><q id='kMkph'><span id='kMkph'><b id='kMkph'><form id='kMkph'><ins id='kMkph'></ins><ul id='kMkph'></ul><sub id='kMkph'></sub></form><legend id='kMkph'></legend><bdo id='kMkph'><pre id='kMkph'><center id='kMkph'></center></pre></bdo></b><th id='kMkph'></th></span></q></dt></tr></i><div id='kMkph'><tfoot id='kMkph'></tfoot><dl id='kMkph'><fieldset id='kMkph'></fieldset></dl></div>
              <tbody id='kMkph'></tbody>
          • <tfoot id='kMkph'></tfoot>
                1. 本文介绍了PHP 多输入搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前正在研究一些 PHP 并且我有 3 个文本输入.在 MySQL 数据库中搜索这些值,并应返回与输入条件相对应的任何数量的结果.

                  这里是搜索表单:

                  <字段集><legend>搜索</legend><div class='container'><label for='C_Name' >企业名称:</label><br/><input type='text' name='C_Name' id='C_Name' maxlength="50"/><br/><label for='C_County' >城市:</label><br/><input type='text' name='C_County' id='C_County' maxlength="50"/><br/><label for='Job_Type' >工作类型:</label><br/><input type='text' name='Job_Type' id='Job_Type' maxlength="50"/><br/>

                  <div class='container'><input type='submit' name='Submit' value='Search'/>

                  </fieldset></表单>

                  这是它在动作中链接的 PHP 脚本:

                   0){//附加条件$query .= " WHERE " .内爆 (' AND ', $conditions);//您可以更改为或",但我建议应用累积过滤器}$result = mysqli_query($mysqli_link, $query) 或 die(mysql_error());mysqli_close($mysqli_link);if(isset($_POST['submit'])) {while($row = mysqli_fetch_assoc($result)) {$C_Name = $row['C_Name'];$C_StreetNumber = $row['C_StreetNumber'];$C_StreetName = $row['C_StreetName'];$C_Postcode = $row['C_Postcode'];$C_County = $row['C_County'];$C_Tele = $row['C_Tele'];$C_Website = $row['C_Website'];$Contact_Forename = $row['Contact_Forename'];$Contact_Surname = $row['Contact_Surname'];$Contact_Email = $row['Contact_Email'];$Job_Type = $row['Job_Type'];$Job_Price = $row['Job_Price'];echo "<b>名称:$C_Name</b><br>街道号码:$C_StreetNumber<br>街道名称:$C_StreetName<br>邮政编码:$C_Postcode<br>县:$C_County<电话>$C_Tele<br>网站:$C_Website<br>联系人姓名:$Contact_Forename $Contact_Surname<br>电子邮件:$Contact_Email<br>工作类型:$Job_Type<br>工作价格<>>工作价格:$Job>;}}}?>

                  由于某种原因它返回有

                  <块引用>

                  意外的文件结尾

                  " 但是我已经检查了代码并且当我在最后添加另一个 '}' 时,所有代码都被正确关闭(从我所看到的)脚本根本不返回任何内容.任何人都知道为什么这会发生吗?

                  来源:使用表单中的多个字段搜索 MySQL 数据库

                  解决方案

                  因为忘记关闭

                  if(isset($_POST['submit'])) {//你没有关闭条件

                  文件末尾

                  只需在文件末尾添加 }

                  I'm currently working on a bit of PHP and I've 3 text inputs. The values are searched in the MySQL database and should return whatever amount of results correspond with the entered criteria.

                  here is the search form:

                  <form id='SearchPersonal' method='post' action='businessUsersSearch.php' accept-charset='UTF-8'>
                  <fieldset >
                  <legend>Search</legend>
                  
                  <div class='container'>
                  <label for='C_Name' >Business Name: </label><br/>
                  <input type='text' name='C_Name' id='C_Name' maxlength="50" /><br/>
                  <label for='C_County' >City: </label><br/>
                  <input type='text' name='C_County' id='C_County' maxlength="50" /><br/>
                  <label for='Job_Type' >Job Type: </label><br/>
                  <input type='text' name='Job_Type' id='Job_Type' maxlength="50" /><br/>
                  </div>
                  
                  <div class='container'>
                  <input type='submit' name='Submit' value='Search' />
                  </div>
                  </fieldset>
                  </form>
                  

                  Here is the PHP script it links too in the action:

                  <?php
                  
                       $mysqli_link = mysqli_connect("server", "database", "pass", "user");
                      // Check connection
                      if (mysqli_connect_errno()) {
                        echo "Failed to connect to MySQL: " . mysqli_connect_error();
                      }
                  
                      if(isset($_POST['submit'])) {
                      // define the list of fields
                       $fields = array('C_Name', 'C_County', 'Job_Type');
                      $conditions = array();
                  
                  
                  // loop through the defined fields
                  foreach($fields as $field){
                      // if the field is set and not empty
                      if(isset($_POST[$field]) && $_POST[$field] != '') {
                          // create a new condition while escaping the value inputed by the user (SQL Injection)
                          $conditions[] = "'$field' LIKE '%" . mysqli_real_escape_string($mysqli_link, $_POST[$field]) . "%'";
                  }
                  }
                  
                  // builds the query
                  $query = "SELECT C_Name, C_StreetNumber, C_StreetName, C_Postcode, C_County, C_Tele, C_Website, Contact_Forename, Contact_Surname, Contact_Email, Jobs.Job_Type, Jobs.Job_Price FROM Company INNER JOIN Jobs ON Company.Company_ID = Jobs.Company_ID";
                  // if there are conditions defined
                  if(count($conditions) > 0) {
                      // append the conditions
                      $query .= " WHERE " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
                  }
                  
                  $result = mysqli_query($mysqli_link, $query) or die(mysql_error());
                  
                  mysqli_close($mysqli_link);
                  
                  
                      if(isset($_POST['submit'])) {
                          while($row = mysqli_fetch_assoc($result)) {
                          $C_Name = $row['C_Name'];
                          $C_StreetNumber = $row['C_StreetNumber'];
                          $C_StreetName = $row['C_StreetName'];
                          $C_Postcode = $row['C_Postcode'];
                          $C_County = $row['C_County'];
                          $C_Tele = $row['C_Tele'];
                          $C_Website = $row['C_Website'];
                          $Contact_Forename = $row['Contact_Forename'];
                          $Contact_Surname = $row['Contact_Surname'];
                          $Contact_Email = $row['Contact_Email'];
                          $Job_Type = $row['Job_Type'];
                          $Job_Price = $row['Job_Price'];
                  
                  echo "<b>Name: $C_Name</b><br>Street Number: $C_StreetNumber<br>Street Name: $C_StreetName<br>Postcode: $C_Postcode<br>County: $C_County<br>Telephone: $C_Tele<br>Website: $C_Website<br>Contact Name: $Contact_Forename $Contact_Surname<br>Email: $Contact_Email<br>Job Type: $Job_Type<br>Job Price: $Job_Price<hr><br>";
                          }
                      }   
                  }
                  
                  ?>
                  

                  For some reason it is returning that there is "

                  unexpected end of file

                  " however I've checked the code and all the codes is closed off correctly (from what I can see) when I add another '}' in at the end the script doesn't return anything at all. Anyone know why this would be happening?

                  Source: Search MySQL Database with Multiple Fields in a Form

                  解决方案

                  Because you forget to close

                  if(isset($_POST['submit'])) {// you not close the condition
                  

                  At the end of your file

                  Just add } at end of your file

                  这篇关于PHP 多输入搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:扩展 MySQLi 类 下一篇:mysqli_query 和 mysqli_real_query 的区别

                  相关文章

                  最新文章

                  <small id='cdJiV'></small><noframes id='cdJiV'>

                    <bdo id='cdJiV'></bdo><ul id='cdJiV'></ul>
                  <tfoot id='cdJiV'></tfoot>

                2. <legend id='cdJiV'><style id='cdJiV'><dir id='cdJiV'><q id='cdJiV'></q></dir></style></legend>

                  <i id='cdJiV'><tr id='cdJiV'><dt id='cdJiV'><q id='cdJiV'><span id='cdJiV'><b id='cdJiV'><form id='cdJiV'><ins id='cdJiV'></ins><ul id='cdJiV'></ul><sub id='cdJiV'></sub></form><legend id='cdJiV'></legend><bdo id='cdJiV'><pre id='cdJiV'><center id='cdJiV'></center></pre></bdo></b><th id='cdJiV'></th></span></q></dt></tr></i><div id='cdJiV'><tfoot id='cdJiV'></tfoot><dl id='cdJiV'><fieldset id='cdJiV'></fieldset></dl></div>