douque9815 2014-12-04 21:54
浏览 39

php中的搜索框与mysql [重复]

This isn't duplicated, since i've tried the search and nothin' i found out worked out for me. SPecially, this code seems to doesn't work with if/else.

i'm trying to search a car in my website, by the name of him in the database. But i'm getting the following error:

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

also, i don't know if i'm using the searchbox button right. I'm giving the action and the link to redirect as the same file, 'cause i think it is easier to put it all together, since it seems simple. Any help ? Here's the codes:

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'];

?>

and the 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>
</div>
  • 写回答

1条回答 默认 最新

  • douou8954 2014-12-04 21:58
    关注

    Your function REQUIRES two arguments:

    function buscarCarros($conexao, $carro){
    

    and you call it with NONE:

    $carro = buscarCarros();
    

    so the error is exactly correct. "missing argument 1".

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c