PHP - 警告:mysqli_fetch_array()
PHP代码:PHP - 警告:mysqli_fetch_array()
<?php
$name = $_GET['name'];
$type = $_GET['type'];
$desc = $_GET['desc'];
$con=mysqli_connect("localhost","root","","projdb");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$res = mysqli_query($con,"SELECT * FROM __scannedfiles WHERE description LIKE '%$desc%' AND title='$name' AND doctype='$type' ");
while($row = mysqli_fetch_array($res)){
$path=$row[3];
echo '<a target=\"_blank\" href="'.$path.'" title=\"\">'.$path.'</a> ';
}
?>
错误:
Warning: mysqli_error() expects exactly 1 parameter, 0 given. this is the error.
这意味着您的查询给错误,传递之前,将使用mysqli_error()
在查询查看错误
$res = mysqli_query($con,"SELECT * FROM __scannedfiles WHERE description LIKE '%$desc%' AND title='$name' AND doctype='$type' ")
OR die(mysqli_error());
这意味着你的查询失败(因为的语法错误或连接错误)。您应该验证并把它传递着,像之前经历:
if($res) {
print "good job!";
}else {
print "error";
}
检查$res
到mysqli_fetch_array
。你会发现它是错误的,因为查询失败。
if($res === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysqli_fetch_array($res)){
$path=$row[3];
echo '<a target=\"_blank\" href="'.$path.'" title=\"\">'.$path.'</a> ';
}
它告诉你,你的查询有问题。查询后执行以下操作:
echo mysqli_error($con);
它会告诉你你的错误在哪里。
这意味着您的查询不会返回任何内容或者有任何不适用的内容。首先调试查询
$res = mysqli_query($con,"SELECT * FROM __scannedfiles WHERE description LIKE '%$desc%' AND title='$name' AND doctype='$type' ") or die('Invalid query: ' . mysqli_error());
第二次检查,如果该行存在
if (mysqli_num_rows($res) > 0) {
while($row = mysqli_fetch_array($res)){
Furhermore你是在sql injection
风险,这里有How can I prevent SQL injection in PHP?看看。您应该使用准备好的声明以避免任何风险
最新错误:警告:mysqli_error()期望恰好有1个参数,给出0。这是错误。 – user2335183 2013-05-03 06:35:43
@ user2335183试试这个或者死(mysqli_error($ con)); – Fabio 2013-05-03 06:38:15
请仔细阅读本手册,该函数在不同情况下可能返回的内容。然后阅读如何获取数据库的错误消息。 – CBroe 2013-05-03 06:23:24
复制粘贴不起作用? – shapeshifter 2013-05-03 06:23:54
我猜__scannedfiles不存在,在任何情况下,运行查询返回false。请检查您的查询。 – 2013-05-03 06:36:05