我正在制作一个PHP
表单,该表单根据输入的序列码从数据库中检索信息。我收到这个错误。我试过移动东西,甚至在 if 语句中调用 $result 函数而不是引用变量。
错误:警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,布尔值在第 22 行的 /home/content/98/10339998/html/scripts/stories.php 中给出
第 20-22 行:
$result = mysqli_query($con, $query);
if (mysqli_num_rows($result))
完整代码:
<?php
if ( $_POST ) {
$username="*******";
$password="*******";
$con = mysqli_connect("storycodes.db.10339998.hostedresource.com",$username,$password);
if (!$con) {
die('Could not connect: ' . mysqli_error());
}
mysqli_select_db($con, "storycodes");
$code = $_POST['codeInput'];
$code = mysqli_escape_string($con, htmlspecialchars($code)); //May not acually need htmlspecialchars
$query = "SELECT story,video FROM `storycodes` WHERE `code` = $code";
$result = mysqli_query($con, $query);
if (mysqli_num_rows($result)) {
$row = mysqli_fetch_assoc($result);
mysqli_free_result($result);
extract($row);
echo $story . $video;
} else {
echo "No Data Found. Please check your serial code to ensure that you have not incorrectly entered it. If the code is correct please email the website administrator for further assistance";
}
mysqli_close($con);
}
?>