$row=mysql_num_rows($result);什么意思,警告:mysqli_num_rows()期望参数1是mysqli_result,在中给出的布尔值...

警告:mysqli_num_rows()期望参数1是mysqli_result,在中给出的布尔值

挣扎着我的网页devise作业。 我一直在按照教程来添加我的网站的searchfunction,但我一直在收到以下错误:

警告:mysqli_num_rows()期望参数1是mysqli_result,在31行/search.php中给出的布尔值

第31行是(或是)

if(mysqli_num_rows($results) >= 1)

那是原来的错误。 根据评论中的说明,我已经修改了代码:

 <?php //capture search term and remove spaces at its both ends if the is any $searchTerm = trim($_GET['keyword']); //check whether the name parsed is empty if($searchTerm == "") { echo "Enter the name/brand of what you're looking for."; exit(); } //database connection info $host = "localhost"; $db_name = "sookehhh_shopsy_db"; $username = "sookehhh_shopsy"; $password = "xxxx"; //connecting to server and creating link to database $link = mysqli_connect($host, $username, $password, $db_name) or die('Could not connect: ' . mysqli_connect_error()); //MYSQL search statement $query = "SELECT * FROM sookehhh_shopsy_db WHERE name LIKE '%" . mysqli_real_escape_string($link, $searchTerm) . "%'"; // original query$query = "SELECT * FROM sookehhh_shopsy_db WHERE name LIKE '%$searchTerm%'"; $results = mysqli_query($link, $query); //added suggestion below - not sure if correct place? if (!$result) { die(mysqli_error($link)); } /* check whethere there were matching records in the table by counting the number of results returned */ if(mysqli_num_rows($results) >= 1) { $output = ""; while($row = mysqli_fetch_array($results)) { $output .= "Product Name: " . $row['name'] . "
"; $output .= "Price: " . $row['price'] . "
"; } echo $output; } else echo "There was no matching record for that item " . $searchTerm; ?>

做了必要的更改并再次更新 –

现在我得到的唯一的错误消息是“表”sookehhh_shopsy_db.sookehhh_shopsy_db'不存在“

我假设我需要更改用户名,也许是因为它太相似了?

无论如何,感谢您的帮助,我对我的完全无知表示歉意。

我一直在试图教自己,但不幸的是时间是我目前没有的奢侈品。

问题是您的查询返回false意味着您的查询中有错误。 查询后,您可以执行以下操作:

if (!$result) { die(mysqli_error($link)); }

或者你可以把它和你的查询结合起来:

$results = mysqli_query($link, $query) or die(mysqli_error($link));

这将打印出你的错误。

另外…你需要清理你的input。 你不能只是把用户input,并把它放入查询。 尝试这个:

$query = "SELECT * FROM shopsy_db WHERE name LIKE '%" . mysqli_real_escape_string($link, $searchTerm) . "%'";

在答复:表'sookehhh_shopsy_db.sookehhh_shopsy_db'不存在

你确定表名是sookehhh_shopsy_db吗? 也许它真的像用户或什么的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值