猿问

如何使用 php 在不同的 html 页面中打开搜索结果

我创建了一个小的搜索栏,它将生成电影详细信息,但我希望结果在单独的 html 页面中打开,你们能帮我解决这个问题吗?


我的代码在下面


<div class="form-container">


        <form method="POST">

            <div class="search-container">

                <input type="text" name="search" placeholder="Search...">

                <button class="btn btn-primary" type="submit" name="submit-search">Search</button>

            </div>

        </form> 

        <div class="resutls">

        <?php


            if (isset($_POST['submit-search'])) {


                $txtresult = $_POST['search'];


                if ($txtresult == 'red') {

                    echo "<span class= 'red'>".$txtresult."</span><br>";

                }elseif ($txtresult == 'green') {

                    echo "<span class= 'green'>".$txtresult."</span><br>";

                }


                function    getImdbRecord($title, $ApiKey)

                    {

                        $path = "http://www.omdbapi.com/?t=$title&apikey=$ApiKey";

                        $json = file_get_contents($path);

                        return json_decode($json, TRUE);


                    }

                $data = getImdbRecord($txtresult, "f3d054e8");  

                echo "<span class = 'info-box'><h3> Name :".$data['Title']."</h3><h3> Year : ".$data['Year']."</h3><h3> Duration : ".$data['Runtime'],"</h3></span>";


    }


        ?>

    </div>


慕莱坞森
浏览 127回答 2
2回答

慕姐4208626

您需要使用表单标签中的 action 参数来指定不同的 HTML/PHP 页面。<form&nbsp;action="otherFile.php"&nbsp;method="POST">然后需要将获取结果的代码移到otherFile.php
随时随地看视频慕课网APP
我要回答