Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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 在表单中使用多个字段搜索MySQL_Php_Html_Mysql_Sql_Forms - Fatal编程技术网

Php 在表单中使用多个字段搜索MySQL

Php 在表单中使用多个字段搜索MySQL,php,html,mysql,sql,forms,Php,Html,Mysql,Sql,Forms,我有个问题要问。 当我从report\u id字段输入值进行搜索时,总是会发生这种情况 警告:mysql\u fetch\u array()希望参数1是资源,布尔值在 . 所有字段都可以搜索,但report\u idfield无法搜索,我不知道如何修复它 if(isset($_POST['submit'])) { // define the list of fields $fields = array('report_name',

我有个问题要问。 当我从
report\u id
字段输入值进行搜索时,总是会发生这种情况
警告:mysql\u fetch\u array()希望参数1是资源,布尔值在
. 所有字段都可以搜索,但
report\u id
field无法搜索,我不知道如何修复它

if(isset($_POST['submit'])) {
              // define the list of fields
                  $fields = array('report_name', 'report_id', 'abstract', 'student_name', 'teacher_name');
                  $conditions = array();
                  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 '%" . mysql_real_escape_string($_POST[$field]) . "%'";
                    }
                  }
                  $query = "SELECT report.report_id, report_year, report_status, report_type, teacher_name, abstract, report_position, report_name,
                  GROUP_CONCAT(student_name ORDER BY student_name ASC SEPARATOR ', ') AS student_name
                  FROM student RIGHT JOIN report ON student.report_id = report.report_id GROUP BY report_name
                  ORDER BY report_name ASC";
// if there are conditions defined
                  if(count($conditions) > 0) {
    // append the conditions
                    $query = "SELECT report.report_id, report_year, report_status, report_type, teacher_name, abstract, report_position, report_name,
                    GROUP_CONCAT(student_name ORDER BY student_name ASC SEPARATOR ', ') AS student_name
                    FROM student RIGHT JOIN report ON student.report_id = report.report_id WHERE " . implode (' AND ', $conditions) . " GROUP BY report_name
                    ORDER BY report_id asc, report_name ASC";
                  }

                  $result = mysql_query($query);
                }
HTML


项目名称

项目ID

关键词

学名

顾问姓名


提交

最有可能导致
警告的原因:mysql\u fetch\u array()希望参数1是resource,在
中给出的布尔值是,您对
的调用返回了FALSE
,因为它无法连接到您的数据库。从:

成功时返回MySQL链接标识符,失败时返回FALSE


为什么所有字段都可以搜索,但只有report\u id字段总是出现警告:mysql\u fetch\u array()希望参数1是资源,布尔值在中给出。
<form action="searching.php" method="post" >
    <p><label>Project Name</label></p>
    <input name="report_name" type="text" class="form-control" placeholder="Enter Report name" id="report_name">
    <p><label>Project ID</label></p>
    <input name="report_id" type="text" class="form-control" placeholder="Enter ID Report" id="report_id">
    <p><label>Keyword</label></p>
    <input name="abstract" type="text" class="form-control" placeholder="Enter Some Keyword" id="abstract">
    <p><label>Student Name</label></p>
    <input name="student_name" type="text" class="form-control" placeholder="Enter Student Name" id="student_name">
    <p><label>Advisor Name</label></p>
    <input name="teacher_name" type="text" class="form-control" placeholder="Enter Advisor Name" id="teacher_name">
    <br><button type="submit" name="submit" class="btn btn-primary" >Submit</button>