0

不可解な IE8 PHP の問題があります。以下のコードは chrome と FF では正常に動作しますが、IE8 では動作しません。フォームが送信され、検索用語またはチェックボックスが選択されていない場合はエラーが表示され、両方のデータベース検索が失敗した場合は、No Actors と No Movies found の両方のエコーが表示されます。しかし、検索のいずれかが成功した場合、何も表示されず、俳優/映画でさえエコーが見つからず、困惑しました.

コードは次のとおりです。

<?php
if($_POST[submitbutton]){
    $search = trim(mysql_real_escape_string($_POST[search]));

    if(!$search){
        echo "Please enter a search term!";
    }else if(!$_POST['checkbox']){
        echo "Please select at least one database to search!";
    }else{
        //search names
        if(in_array("actors", $_POST['checkbox'])){
            $query = mysql_query("SELECT name_id, realname, mainalias FROM names WHERE realname LIKE '%$search%' OR mainalias LIKE '%$search%'");

            if(mysql_num_rows($query)==0){
                echo "<h2>No Actors by that name found!</h2>", "<p>";
            }else{
                echo "<h2>Actors Found:</h2>";
                while ($record = mysql_fetch_assoc($query)){
                    $realname = $record['realname'];
                    $name_id = $record['name_id'];
                    echo "<a href='index.php?page=name&id=$name_id'>", $realname, "</a><hr>";
                }
            }
        }

        //search titles
        if(in_array("movies", $_POST['checkbox'])){
            $query = mysql_query("SELECT title_id, title FROM titles WHERE title LIKE '%$search%'");

            if(mysql_num_rows($query)==0){
                echo "<h2>No Movies by that name found!</h2>", "<p>";
            }else{
                echo "<h2>Movies Found:</h2>";
                while ($record = mysql_fetch_assoc($query)){
                    $title = $record['title'];
                    $title_id = $record['title_id'];
                    echo "<a href='index.php?page=title&amp;id=$title_id'>", $title, "</a><br>";

                echo "<hr>";
                }
            }
        }
    }
} //end post submitbutton
?>
4

2 に答える 2

0

したほうがいい

$search = trim(mysql_real_escape_string($_POST[search]));

なれ

$search = trim(mysql_real_escape_string($_POST['search']));

それがあなたの問題と関係があるかどうかはわかりませんが、私には飛びつきます.

于 2012-06-01T15:32:37.280 に答える
0
<?php
if(isset($_POST['submitbutton'], $_POST['search'])){ //use isset for check exists vars
    $search = trim(mysql_real_escape_string($_POST['search'])); // ['POST vars']

    if(!$search){
        echo "Please enter a search term!";
    }else if(!isset($_POST['checkbox'])){
        echo "Please select at least one database to search!";
    }else{
        //search names
        if(in_array("actors", $_POST['checkbox'])){
            $query = mysql_query("SELECT name_id, realname, mainalias FROM names WHERE realname LIKE '%$search%' OR mainalias LIKE '%$search%'");

            if(mysql_num_rows($query)==0){
                echo "<h2>No Actors by that name found!</h2>", "<p>";
            }else{
                echo "<h2>Actors Found:</h2>";
                while ($record = mysql_fetch_assoc($query)){
                    $realname = $record['realname'];
                    $name_id = $record['name_id'];
                    echo "<a href='index.php?page=name&id=$name_id'>", $realname, "</a><hr>";
                }
            }
        }

        //search titles
        if(in_array("movies", $_POST['checkbox'])){
            $query = mysql_query("SELECT title_id, title FROM titles WHERE title LIKE '%$search%'");

            if(mysql_num_rows($query)==0){
                echo "<h2>No Movies by that name found!</h2>", "<p>";
            }else{
                echo "<h2>Movies Found:</h2>";
                while ($record = mysql_fetch_assoc($query)){
                    $title = $record['title'];
                    $title_id = $record['title_id'];
                    echo "<a href='index.php?page=title&amp;id=$title_id'>", $title, "</a><br>";

                echo "<hr>";
                }
            }
        }
    }
} //end post submitbutton
?>
于 2012-06-01T17:16:15.910 に答える