我在mysqli中编写了一个php表格搜索表,它工作正常,但是如果没有找到结果,我想向用户显示正确的消息。检查是否没有在MySQL数据库中找到结果
这里是我当前的代码:
$search_string=$_GET["design"];
$connect= mysqli_connect("mysql.myhost.com","abc","123456","mydb_db");
$query="select * from product where product_design like '%$search_string%'";
$rows= @mysqli_query($connect,$query) or die("Error: ".mysqli_error($connect));
if ($rows!=null)//I put this if to check if there is any result or not but its not working
{
while(($record=mysqli_fetch_row($rows))!=null)
{
.
.//i have working code for showing the result here
.
}
mysqli_close($connect);
}
else{
echo"no result found";
}
能否请你帮我什么是错的,甚至当我搜索一些东西,是不是在DB仍然没有显示程序“没有结果发现”存在
谢谢
尝试将'$ rows!= null'更改为'$ rows> 0' – lemonpole
希望没有人运行设计=''; DROP TABLE产品的GET请求;' –
要扩展@ Phil的观点,您的代码是非常容易受到[SQL Injection](http://php.net/manual/en/security.database.sql-injection.php)的攻击。这意味着任何使用您的网站的人都可以对数据库做任何事情。考虑使用参数化查询(谷歌它), – Basic