0

Firefox、サファリなどでは正常に機能しますが、クロムでは機能しない検索クエリ スクリプトがあります。

なんらかの理由で、ユーザーがクエリを入力して送信すると、URL が大きく異なることに気付きます。

クロムでは、これが機能し、正しいものを取得します

http://localhost/ptb1/home.php?query=london&submit.x=0&submit.y=0&submit=Start+Search

しかし、Firefoxではこれを取得します(統計+検索が欠落していて、理由がわからないことに注意してください

http://localhost/ptb1/home.php?query=london&submit.x=12&submit.y=10

なぜ私がこの問題を抱えているのか、そしてそれを正しくする方法を教えてください。ありがとう。

ここに私のコードがあります:

<form method="get" action="">
<input type="text" id="text" name="query" class="searchbox" placeholder="Search Name/Location" style="width:120px;"/>
<input type="image" src="../PTB1/assets/img/icons/search.png" height="19" width="20" class="searchbutton" name="submit" value="Start Search" />
</form>

<?php
//PHP CODE STARTS HERE

if(isset($_GET['submit'])){

// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
$db_password="";
$db_name="";
$db_tb_atr_name="display_name";

//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen

mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");

$query=mysql_real_escape_string($_GET['query']);


$query_for_result=mysql_query("SELECT *,MATCH(display_name, location, sex, ethnicity, hobbies, station, age, weight_st, weight_lb, height_ft, height_in, build) AGAINST ('$query' IN BOOLEAN MODE) AS relevance FROM ptb_stats WHERE MATCH(display_name, location, sex, ethnicity, hobbies, station, age, weight_st, weight_lb, height_ft, height_in, build) AGAINST('$query' IN BOOLEAN MODE) ORDER BY relevance DESC LIMIT 5");
echo "<div class=\"search-results\">";
while($data_fetch=mysql_fetch_array($query_for_result))

{

    echo "<div class=\"text\"><a href=\"profile.php?id={$data_fetch['user_id']}\" class=\"search\">";
    echo "<div class=\"spacing\"><img width=35px height= 30px src=\"data/photos/{$data_fetch['user_id']}/_default.jpg\" class=\"boxgridsearch\"/> "; 
     echo substr($data_fetch[$db_tb_atr_name], 0,160);
    echo "</a></div></div>";

}
echo "<div class=\"morebutton-search\"><a href=\"search_results.php?query=$query\" \">+ view more results</a></div>";




mysql_close();
}

?>



<style type="text/css">



.boxgridsearch{ 
                width: 35px; 
                height: 30px; 
                margin-top:-3px;
                margin-left:0px; 
                margin-right:10px; 
                float:left; 
                background:#161613; 
                        border:4px solid #000 .8;
    -moz-box-shadow: 0px 0px 8px #CCC;
    -webkit-box-shadow: 0px 0px 0px #CCC;
    box-shadow: 0px 3px 10px #030303;



            }


    .suggestionsBox {
        position: relative;
        left: 12px;
        margin: 10px 0px 5px 0px;
        width: 172px;
        background-color: #FFF;
        border: 1px solid #CCC; 
        color: #fff;
        z-index:99;
    }

    .searchbutton {

        padding-top: 2px;
        padding-left:5px;
        position:absolute;
        z-index:70;

    }


    .spacing {

        padding-top: 12px;
        padding-bottom:12px;
        border-bottom: solid #CCC 1px;
        border-top: solid #CCC 1px;
        text-align:left;
        margin-left:0px;
        margin-top:5px;
        width:160px;


    }

    .text {
        text-align:left;
        margin-left:20px;
        margin-top:0px;
        width:200px;


    }


        .search-results {
    width: 200px;
    height:218px;
    float: left;

    margin-bottom: 20px;
    margin-left: 0px;
    margin-top:10px;
    text-align: center;

    /* [disabled]margin-left: 30px; */
    overflow: hidden;
    padding-top: 0px;
    padding-bottom: 10px;


}   


    .searchbox {

        margin-left: -25px;





    }


    .suggestionList {
        margin: 0px;
        padding: 0px;

    }

    .suggestionList li {

        margin: 0px 0px 3px 0px;
        padding: 3px;
        cursor: pointer;
    }

    .suggestionList li:hover {
        background-color: #659CD8;
    }


    a.search {
    color: #646464;
    text-decoration: none;
}
a.search:visited {
    color: #646464;
}
a.search:hover {
    color: #646464;
    text-decoration: none;
}
a.search:active {
    color: #646464;
}




</style>
4

2 に答える 2

0

ブラウザーは、そのフォームが異なる方法で送信される方法を解釈します。Firefox で見られる動作は、実際には起草された標準です: http://www.whatwg.org/specs/web-apps/current-work/multipage/

ボタンのスタイリングと画像の使用 (送信、画像入力タイプ、ボタン) を掘り下げることができる場所 - 最も簡単な修正は、非表示の入力値をフォームに追加することです。

<form method="get" action="">
    <input type="hidden" name="dosearch" value="1">
    <input type="text" id="text" name="query" class="searchbox" placeholder="Search Name/Location" style="width:120px;"/>
    <input type="image" src="../PTB1/assets/img/icons/search.png" height="19" width="20" class="searchbutton" name="submit" value="Start Search" />
</form>

次に、PHP で処理するための条件を微調整します。

if(isset($_GET['dosearch'])){

クイックパッチ。

これをたくさん行う場合は、フレームワークを検討する必要があります。この種のロジックは、非常にクリーンで階層化されたコード (MVC) で無料で入手できます。

于 2013-02-04T04:02:24.400 に答える
0

基本的に$_SERVER['REQUEST_METHOD']ではなく、ページが送信されたかどうかを判断するために 使用することができます。isset($_GET['submit'])

if(isset($_GET['submit'])){

// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";

あなたがやる:

if($_SERVER['REQUEST_METHOD'] == 'GET'){

// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
于 2013-02-04T03:53:03.827 に答える