Why can't I find a record in the result database for this multi-condition search code? however, when querying the response record, "database query failed!" is displayed! & Lt; br & gt; there may be no records in the database. "What is the problem? Search Code: & nbsp; & lt; formid & quot; form1 & quot; name & quot; form1 & quot; method & quot; get & quot; action & ask why the multi-condition search code cannot be found
There are records in the database, but when querying the response records, it shows "database query failed!
There may be no records in the database. "What is the problem?
Search code:
Query code:
$ Word = $ _ GET ['word']; // Obtain the keyword
$ Mode = $ _ GET ['mode']; // obtain the search method
If (! Empty ($ word )){
Echo' Queryable';
Echo 'The keyword you are querying is: ', $ word ,'"
';
$ SQL = "SELECT * FROM". SqlTableName;
Switch ($ mode)
{
Case's _ all': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'name' LIKE '% $ word %' OR 'Birthday' LIKE '% $ word %'
OR 'QQ' LIKE '% $ word %' OR 'mobile' LIKE '% $ word %'
OR 'email 'LIKE' % $ word % 'OR 'address' LIKE' % $ word % '"; break;
Case's _ name': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'name' LIKE '% $ word %' "; break;
Case's _ birthday ': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'birthday' LIKE '% $ word %' "; break;
Case's _ QQ': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'QQ' LIKE '% $ word %' "; break;
Case's _ mobile': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'mobile' LIKE '% $ word %' "; break;
Case's _ email ': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'email 'LIKE' % $ word % '"; break;
Case's _ address ': $ SQL = 'select * FROM ''. SqlDataBase.''. ''. SqlTableName ."'
WHERE 'address' LIKE '% $ word % ''; break;
Default: $ SQL = "SELECT * FROM" '. SqlTableName .""';
}
Require ('Conn. php'); // call the conn. php file to perform database operations
$ Result = mysqli_query ($ conn, $ SQL) or die ('database query failed!
There may be no records in the database '); // the SQL statement is executed here
If ($ result)
{
Echo $ result;
}
}
Else
{
Echo' ', $ Word ,'';
}
?>
------ Solution --------------------
$ SQL = 'select * FROM 'mycg '. 'Providers 'Where 'address' LIKE' % $ word %''
Change
$ SQL = "SELECT * FROM 'mycg '. 'Providers 'Where 'address' LIKE' % $ word % '"
------ Solution --------------------
Failed to query die ('database!
There may be no records in the database ');
Change to die ("$ SQL
". Mysql_error ());
In this way, you can see why the error occurs.
Switch writes are too messy to check correctness
------ Solution --------------------
First, echo $ SQL; query the statement to the mysql terminal and execute it to see if the returned results are normal.
------ Solution --------------------