我从mysql改为mysqli,我现在得到所有这些错误,我似乎无法修复。我有结果集,它说我没有。
警告:mysqli_fetch_assoc()要求参数1为mysqli_result,第26行/home/content/98/10339998/html/scripts/stories.php中给出布尔值
我认为一旦数组被整理出来,这个警告应该自行解决:
警告:extract()要求参数1为数组,在第28行的/home/content/98/10339998/html/scripts/stories.php中给出null
警告:mysqli_free_result()要求参数1为mysqli_result,第30行/home/content/98/10339998/html/scripts/stories.php中给出布尔值
$con = mysqli_connect("storycodes.db.10339998.hostedresource.com",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysqli_select_db($con, "storycodes");
$code = $_POST['codeInput'];
$code = htmlspecialchars($code);
$query = "SELECT story,video FROM `storycodes` WHERE `code` = $codeInput";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_assoc($result);
extract($row);
mysqli_free_result($result);
mysqli_close($con);
echo $story . $video;
答案 0 :(得分:1)
如果不切换到mysqli,请使用以下代码:
$code = $_POST['codeInput'];
$code = mysqli_escape_string(htmlspecialchars($code)); //May not acually need htmlspecialchars
$query = "SELECT story,video FROM `storycodes` WHERE `code` = 'code'";
$result = mysqli_query($con, $query);
将mysqli与预处理语句一起使用是更好的选择,但这可以解决您的问题,而无需添加大量工作。