使用who是我的代表性API (whoismyrepresentative.com )和get命令,不会在索引页面上呈现输入字段的结果,请求提供邮政编码。语法是否不正确,是否需要回显命令?
我创建的索引页:
<section class="form-one">
<form action="search-results.php" method="post">
<label for="zipcode"> Input Zipcode</label>
<input id="zipcode" type="number" name="zip" size="5">
<input type="submit" name="">
</form>
</section>the页面,其中我调用GET命令:
<?php
file_get_contents('https://whoismyrepresentative.com/getall_mems.php?zip=&output=json'.$_GET['zip'].'php?zip=&output=json …');
/*echo $_GET["https://whoismyrepresentative.com/getall_mems.php?zip=&output=json …"];*/
?>命令应该输出json。
发布于 2019-01-05 04:08:14
在查看了您的活动站点和API之后,您的问题归结为两个错误。
要使用GET,需要更新HTML表单方法以获得-
<section class="form-one">
<form action="search-results.php" method="get">
<label for="zipcode"> Input Zipcode</label>
<input id="zipcode" type="number" name="zip" size="5">
<input type="submit" name="">
</form>
</section>然后,PHP中也会出现问题,在PHP中,您没有用正确的参数调用正确的URL,也没有分配和回显正确的响应。这会将JSON返回给$json_rep,并将json解码为一个数组$rep_array,允许您循环遍历代表并执行您需要做的事情。
<?php
$json_rep = file_get_contents('https://whoismyrepresentative.com/getall_mems.php?zip='.$_GET['zip'].'&output=json');
$rep_array = json_decode($json_rep);
var_dump($rep_array);
?>发布于 2019-01-05 03:01:46
这将起作用:
file_get_contents('https://whoismyrepresentative.com/getall_mems.php?zip=' . $_GET['zip'] . '&output=json');发布于 2019-01-05 03:36:28
您将表单设置为发出post请求。您可以通过两种方式修复代码。
https://stackoverflow.com/questions/54048582
复制相似问题