Why can't I find the result of this multi-condition search code?

Source: Internet
Author: User
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 --------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.