我创建了一个小的搜索栏,它将生成电影详细信息,但我希望结果在单独的 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>
2 回答

慕姐4208626
TA贡献1852条经验 获得超7个赞
您需要使用表单标签中的 action 参数来指定不同的 HTML/PHP 页面。
<form action="otherFile.php" method="POST">
然后需要将获取结果的代码移到otherFile.php
- 2 回答
- 0 关注
- 126 浏览
添加回答
举报
0/150
提交
取消