0

我有一个莫名其妙的 IE8 PHP 问题。下面的代码在 chrome 和 FF 中运行良好,但在 IE8 中运行良好。表单正在提交,如果没有选择搜索词或​​复选框,则会显示错误,如果两个 db 搜索都失败,则会显示 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
<?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 回答
0

应该

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

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

我不知道这是否与你的问题有关,但它跳到我身上。

于 2012-06-01T15:32:37.280 回答