我猜这个问题是重复的,但我不明白我的MYSQLi提取有什么错误
的错误时,我不喜欢一些世界数据库中搜索任何东西不是在数据库例如,当我搜索我得到足球我得到的错误味精,但是当我搜索平面其返回结果(平面是在数据库中)
这是search.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db";
$conn = new mysqli($servername, $username, $password, $dbname);
$searchTerm = $conn->real_escape_string($_POST['term']);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else{
$sql = "SELECT user_st,username FROM users WHERE user_st LIKE '%'".$searchTerm."'%'";
$result = $conn->query($sql);
$count = $result->num_rows;
if($count){
echo "data found</br></br>";
while ($info = $result->fetch_assoc()) {
echo $info['user_st'];
echo "</br>";
}
}else{
echo "No info Founded";
}
}
$conn->close();
错误msg正在尝试获取第21行 错误C:\ wamp \ www \ mysqli_login \ search.php中非对象的属性错误msg这是什么意思?
问题是您要用附加的单引号中断查询。
您必须更改以下代码
'%'".$searchTerm."'%'
对此:
'%".$searchTerm."%'
^ ^
dropped the single quotes here (^)
也许mysqli_error()
有时是有益的认识到这种类型的错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句