douwen3127 2015-01-24 16:35
浏览 32
已采纳

警告:mysql_fetch_assoc()期望参数1是资源,第12行给出布尔值[重复]

i am getting this error and i can't find boolen. Can somebody help please?

if(isset($_POST['search_term'])){
$search_term = mysql_real_escape_string(htmlentities($_POST['search_term']));
if (!empty($search_term)){
    $search = mysql_query ("SELECT `username` FROM  `users ` WHERE  `users` LIKE '%search_term%'");

    while ($results_row = mysql_fetch_assoc($search)){
        echo '<p>',$results_row['username'],'</p>';
    }
}

}
?>


  • 写回答

1条回答 默认 最新

  • duanqian6982 2015-01-24 16:38
    关注

    This part of your script '%search_term%' is missing the $

    change that to '%$search_term%'

    and remove the space in your table name

    `users `
          ^
    

    as Mario stated. You will have an unknown table name. Kudos to Mario.

    While you're at it, switch to mysqli_ or PDO. You'll eventually have to switch; it's deprecated and will be removed in future PHP releases.

    Also add or die(mysql_error()) to mysql_query() to catch errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?