mysqli_real_escape_string
使程序错误。
我有一个全文列title
。
我完成后,全文功能不在phpMyadmin中工作。
PHPMYADMIN
- **id|title**
- 1|cool boy
- 2|cool bottle
- 3|cool guy
- 4|hot man
更新
file1.php
//from a form
$str = $_POST['q'];
$str=mysqli_real_escape_string($con,$str);
mysqli_query($con,"insert into tbl(title)values($str)");
file2.php
$str = $_GET['q'];
$data = mysqli_query($con,"select * from tbl where match(title)against('$str')");
while($row = mysqli_fetch_assoc($data)){
//do stuff . but yields nothing
}
答案 0 :(得分:0)
试试这个
select * from tbl where title LIKE '%cool%'
编辑:如果您想进行全文搜索,请更改此
against('cool')
到
against('cool' IN BOOLEAN MODE)
在MySQL中,有三种类型的全文搜索:
来自MySQL manual entry:
EDIT2:
在file1.php中执行
session_start(); //this will be in very top of your file
$str = $_POST['q'];
$_SESSION['str'] = $str;
$str=mysqli_real_escape_string($con,$str);
mysqli_query($con,"insert into tbl(title)values($str)");
在file2.php中
session_start(); //this will be in very top of your file
$str = $_SESSION['str'];
$data = mysqli_query(.........
答案 1 :(得分:0)
select * from tbl where title LIKE 'cool%'
在字符串/变量
之后只添加一个%