php - php中的搜索框与mysql

标签 php html mysql

这个问题在这里已经有了答案:





mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

(31 个回答)


7年前关闭。




这不是重复的,因为我已经尝试过搜索,但没有发现对我有用。特别是,此代码似乎不适用于 if/else。

我试图在我的网站上搜索一辆车,在数据库中按他的名字。但我收到以下错误:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/u374984363/public_html/newcars/functions.php on line 61

另外,我不知道我是否使用了正确的搜索框按钮。我将重定向的 Action 和链接作为同一个文件提供,因为我认为将它们放在一起更容易,因为它看起来很简单。有什么帮助吗?这是代码:
functions.php :

function buscarCarros($conexao, $nome){
    $carro = array();
    $conexao = mysqli_connect('mysql.hostinger.com.br','u374984363_ozzy','ozzy@123', 'u374984363_ncars');
    $query = "select * from carros where nome = {$carro}";
    $resultado = mysqli_query($conexao, $query);
    while ($carros = mysqli_fetch_assoc($resultado)) {
        array_push($carro, $carros);
    }
    return $carro;
}
result_pesquisa.php :
<?php
include('menu.php');
include('conecta.php');
include('functions.php');

$carro = buscarCarros($conexao, $nome);
    foreach ($carro as $carros) :
        $carros['nome'];

?>

menu.php :
<nav class="twelve columns">
            <ul class="menu">
                <li class="menu-item"><a href="index.php">Home</a></li>
                <li class="menu-item"><a href="comprar.php">Comprar</a></li>
                <li class="menu-item"><a href="">Vender</a></li>
                <li class="menu-item"><a href="">Contato</a></li>
            </ul>
            <form id="searchbox" action="result_pesquisa.php">
                <input type="text" class="search-top remove-bottom" name="pesquisas" placeholder="Qual carro você procura?">
                <!-- <a href="javascript:document.getElementById('searchbox').submit();"> -->
                <a href="result_pesquisa.php"><span class="icon-top icon-search"></span></a>
            </form>
        </nav>

最佳答案

您的功能需要 两个论点:

function buscarCarros($conexao, $carro){

你用 调用它无 :
$carro = buscarCarros();

所以这个错误是完全正确的。 “缺少参数 1”。

关于php - php中的搜索框与mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27304853/

相关文章:

javascript - 为克隆输入提供输入 'name' 属性,该属性位于列表内

html - CSS 悬停 : Bold changing element size with padding

php - 使用mysql处理多个用户

php - 如何在 PHP 中从 .GPX 文件中读取值?

PHP - 多个 bind_params 失败

html - Bootstrap : Fixed div flows outside container

mysql - SQL根据某些条件将3个表中的数据合并到第4个表中

php - Codeigniter URI 路由和安全

php - PHP 7.4 中的空合并赋值 ??= 运算符是什么

mysql - 无法使用 "if not exists"创建 MySQL 表