below is my php snippet please how do i make my search to return result when i search for john doe am using a single search box in my php form with fname and lname saved in different column in my database. i only recive result when only fname or lname is searched.
下面是我的php片段,当我搜索john doe时,如何使用我的php表单中的单个搜索框,我的搜索返回结果,fname和lname保存在我的数据库的不同列中。我只搜索只搜索fname或lname时的结果。
$search_string = " AND (fname LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR lname LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%')";
1 个解决方案
#1
1
Please use MySQLi or PDO. mysql_* is deprecated and insecure.
请使用MySQLi或PDO。 mysql_ *已弃用且不安全。
I no longer use mysql_* so this syntax may be incorrect, but this should work:
我不再使用mysql_ *所以这个语法可能不正确,但这应该工作:
$search = "Joe Bloggs";
$query = "SELECT * FROM users WHERE fname LIKE %$search% OR lname LIKE %$search%";
#1
1
Please use MySQLi or PDO. mysql_* is deprecated and insecure.
请使用MySQLi或PDO。 mysql_ *已弃用且不安全。
I no longer use mysql_* so this syntax may be incorrect, but this should work:
我不再使用mysql_ *所以这个语法可能不正确,但这应该工作:
$search = "Joe Bloggs";
$query = "SELECT * FROM users WHERE fname LIKE %$search% OR lname LIKE %$search%";