无法在php中使用mysqli从数据库中检索数据


cannot retrieve data from database with mysqli in php

我有一些麻烦弄清楚到底是什么是错误的我的代码,我似乎无法从我的数据库检索数据。

我在php检查器上绝对没有错误,它以前在测试之前工作过,然后我扩展了代码以具有更好的搜索模式,现在通过编码的一半突然停止工作,我无法找出问题。

我知道连接到我的数据库工作,因为我使用它为我的网站的另一部分。

对此事的任何帮助都将非常感激。

<?php
            include("search/dbconnect.php");
            $count;
            $searchtext= $_POST['search-box'];
            $searchbit=explode(" ", $_POST['search-box']);
            $searchsound= metaphone($_POST['search-box']);
            $sqlName="SELECT * FROM SearchPG WHERE PGName LIKE '%".$_POST['search-box']."%'";
            $sqltext="SELECT * FROM SearchPG WHERE PGName LIKE '%".$_POST['search-box']."%' OR PGKeywords LIKE '%".$_POST['search-box']."%' ";
            $sqlsound="SELECT metaphonetext.*, SearchPG.* FROM metaphonetext JOIN SearchPG ON metaphonetext.PGID=SearchPG.PGID WHERE metaphonetext.NameSound LIKE '%".$searchsound."%'";
            $qryname=mysqli_query($dbconnect, $sqlName);
            $qrytext=mysqli_query($dbconnect, $sqltext);
            $qrysound=mysqli_query($dbconnect, $sqlsound);
            if(mysqli_num_rows($qryname)>0){
                $rs=mysqli_fetch_assoc($qryname);
                do{
                    ?>
                    <div class="row resultcontent">
                        <a href="<?php echo $rs['PGUrl'];?>">
                            <div class="col-sm-8 searchRsltCont">
                                <img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
                                <div class="contshading">
                                </div>
                            </div>
                            <div class="col-sm-4 searchRslttxt">
                                <h1><?php echo $rs['PGName'];?></h1>
                            </div>
                        </a>
                    </div>
                    <?php
                    $count++;
                } while($rs=mysqli_fetch_assoc($qryname));
            } elseif(mysqli_num_rows($qrytext)>0){
                foreach($searchbit as $value){
                    $temp = $value;
                    $sqltext="SELECT * FROM SearchPG WHERE PGName LIKE '%".$temp."%' OR PGKeyword LIKE '%".$temp."%' ";
                    $qrytext=mysqli_query($dbconnect, $sqltext);
                    $rs=mysqli_fetch_assoc($qrytext);
                    do{
                    ?>
                        <div class="row resultcontent">
                        <a href="<?php echo $rs['PGUrl'];?>">
                            <div class="col-sm-8 searchRsltCont">
                                <img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
                                <div class="contshading">
                                </div>
                            </div>
                            <div class="col-sm-4 searchRslttxt">
                                <h1><?php echo $rs['PGName'];?></h1>
                            </div>
                        </a>
                    </div>
                    <?php
                    $count++;
                } while($rs=mysqli_fetch_assoc($qrytext));
                }
            } elseif(mysqli_num_rows($qrysound)>0){
                $rs=mysqli_fetch_assoc($qrysound);
                do{
                    ?>
                    <div class="row resultcontent">
                        <a href="<?php echo $rs['PGUrl'];?>">
                            <div class="col-sm-8 searchRsltCont">
                                <img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
                                <div class="contshading">
                                </div>
                            </div>
                            <div class="col-sm-4 searchRslttxt">
                                <h1><?php echo $rs['PGName'];?></h1>
                            </div>
                        </a>
                    </div>
                    <?php
                    $count++;
                } while($rs=mysqli_fetch_assoc($qrysound)); 
            }else{
                foreach($searchbit as $value){
                    $temp = metaphone($value);
                    $sqlsound="SELECT metaphonetext.*, SearchPG.* FROM metaphonetext JOIN PGName ON metaphonetext.PGID=SearchPG.PGID WHERE metaphonetext.NameSound LIKE '%".$temp."%'";
                    $sqlsoundkey="SELECT metaphonetext.*, SearchPG.* FROM metaphonetext JOIN PGKeywords ON metaphonetext.PGID=SearchPG.PGID WHERE metaphonetext.KeywordSound LIKE '%".$temp."%'";
                    $qrysound=mysqli_query($dbconnect, $sqlsound);
                    $qrysoundkey=mysqli_query($dbconnect, $sqlsoundkey);
                    if(mysqli_num_rows($qrysound)>0){
                        $rs=mysqli_fetch_assoc($qrysound);
                        do{
                        ?>
                            <div class="row resultcontent">
                                <a href="<?php echo $rs['PGUrl'];?>">
                                    <div class="col-sm-8 searchRsltCont">
                                        <img src="<?php echo $rs['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
                                        <div class="contshading">
                                        </div>
                                    </div>
                                    <div class="col-sm-4 searchRslttxt">
                                        <h1><?php echo $rs['PGName'];?></h1>
                                    </div>
                                </a>
                            </div>
                        <?php
                        } while($rs=mysqli_fetch_assoc($qrysound));
                    }else if(mysqli_num_rows($qrysoundkey)>0){
                        $rskey=mysqli_fetch_assoc($qrysoundkey);
                        do{
                        ?>
                            <div class="row resultcontent">
                                <a href="<?php echo $rskey['PGUrl'];?>">
                                    <div class="col-sm-8 searchRsltCont">
                                        <img src="<?php echo $rskey['PGImgUrl'];?>" class="searchRsltimg" alt="search result image" />
                                        <div class="contshading">
                                        </div>
                                    </div>
                                    <div class="col-sm-4 searchRslttxt">
                                        <h1><?php echo $rskey['PGName'];?></h1>
                                    </div>
                                </a>
                            </div>
                        <?php
                        } while($rs=mysqli_fetch_assoc($qrysoundkey));
                    }else if(mysqli_num_rows($qrysound)<=0 && mysqli_num_rows($qrysoundkey)<=0){
                        ?>
                        <p>no results found</p>
                        <?php
                    }else{
                        ?>
                            <p>no more results found</p>
                        <?php
                    }
                }

            }
        ?>

感谢大家指出我代码中的缺陷,如果我没有在这里发布,我不会知道这一点,直到我的数据库被攻击,我现在正在努力修复它们。我发现我的问题不是代码,虽然它更多地与我缺乏知识有关,你看到测试后,我将我的dbconnection参数移动到一个ini文件,并将它们存储在我的根文件夹之外,以保证它的安全,在那里,dbconnection变量然后成为一个局部变量,基本上在变量存储的文件夹之外不可用。解决方案很简单,我只是把我的搜索引擎移动到相同的文件夹