douraoyw194498 2014-10-04 06:20
浏览 56
已采纳

致命错误:在第43行的C:\ xampp \ htdocs \ projectname \ searchit.php中的非对象上调用成员函数mysqli_fetch_array()[关闭]

I know this question has been asked several times, however I can still not get this to work!!!

I am trying to make a basic search engine which I manually enter pages etc in a phpMyadmin mysql databse. The error that keeps coming up is:

Fatal error: Call to a member function mysqli_fetch_array() on a non-object in C:\xampp\htdocs\projectname\searchit.php on line 43

So here is the code!!!

<html lang="en">
<head>
<meta charset="utf-8">
<title>
Search The Internet
</title>
<link rel="stylesheet" href="main.css">
<div id="menu_bar1" style="padding:10px; margin: 0px;">
<form action="searchit.php" method="GET"> 
<label>Search
</label>
<input type="text" name="lets_search_for" size="50" placeholder="What do you want to search for???"/>
<input type="submit" name="search" value="Lets Search!!!"/>
</form>
</div>
</head>
<body bgcolor="#8E44AD">    
<?php    
  if (isset($_GET['search']))    
  {    
    $mysqli = mysqli_connect("localhost", "root", "Password");  
    $search_val = $_GET['lets_search_for'];
    echo "What Did We Find??? For <b><i> $search_val </i></b>" ;
    print "<br />";    
    $query = "SELECT * FROM search_websitename WHERE keywords LIKE ' . %$search_val% .'"; 
    $result = $mysqli->query($query);

   if($mysqli === FALSE) {
        die(mysqli_error()); 
   }    
   while ($row = $result->mysqli_fetch_array($query) ){  //This is line 43!!!

      $title = $row['title'];
      $link = $row['url'];
      $des = $row['des'];   

      echo "<a href='$link'>$title</a><br />";
      echo $link;
      echo "<p>" .
      $des . "</p><hr /><br />";    
    }    
}    
?>    
</body>    
</html>
  • 写回答

2条回答 默认 最新

  • duanjing9739 2014-10-04 06:28
    关注

    You need to fix the following:

    $mysqli = mysqli_connect("localhost", "root", "Password");
    // missing database connection
    
    $search_val = $_GET['lets_search_for'];
    
    $query = "SELECT * FROM search_websitename WHERE keywords LIKE ' . %$search_val% .'";
    // you do not need a dot (concatenation)
    

    So finally:

    $mysqli = mysqli_connect("localhost", "root", "Password", "DATABASE_NAME");
    $search_val = $_GET['lets_search_for'];
    $search_val = '%' . $mysqli->real_escape_string($search_val) . '%';
    $query = "SELECT * FROM search_websitename WHERE keywords LIKE '$search_val' ";
    $result = $mysqli->query($query);
    while ($row = $result->fetch_assoc() ) {
        echo $row['whaatever_column_name'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化