表单php无法正常工作[array]

时间:2017-08-18 11:52:44

标签: php html

我需要显示var_dump与所选国家' , 但我不能这样做,因为$ res(array)$ id

中存在问题
<?php
if(isset ($_POST['submit']))
{
    $id = $_POST['cata'];

    $api = new SoapClient ( 'http://www.webservicex.com/globalweather.asmx?WSDL' );
    $res = $api->GetCitiesByCountry(array( 'CountryName' =>"$id"));

    var_dump($res);
}
?> 

<form action="" name="cata">
    <select>
        <option>Israel</option>
        <option>Egypt</option>
    </select>
    <br>
    <input id='sumbit' name='submit' type='submit' value='tim'>
</form>

仍然无法正常工作,但我认为

中的问题

&#13;
&#13;
  $res = $api->GetCitiesByCountry(array( 'CountryName' =>"$id"));
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:0)

您需要将名称设为cata以选择不形成标记的标记

<select name="cata"><option>Israel</option><option>Egypt</option></select>

还将方法post放在表单标记

<form action="" method="post">

我认为网络服务正在运作:http://www.webservicex.com/globalweather.asmx?WSDL&CountryName=Israel

答案 1 :(得分:0)

cata定义为select名称而不是form名称

所以定义下面的表格

<form action="" method="post"> //<--- also set method for retrieving data in php 
  <select name="cata"> //<--here is the name field
      <option>Israel</option>
      <option>Egypt</option>
  </select>
  <br>
  <input id='sumbit' name='submit' type='submit' value='tim'>
</form>

并在php中设置

$id = $_POST['cata']

答案 2 :(得分:0)

尝试运行此代码段。它应该适合你。 &#34; Alive to Die&#34;片段是未设置选项的值。

<?php
    error_reporting(E_ALL); //check all type of error
    ini_set('display_errors', 1); // display those errors

    if (isset($_POST['submit'])) {
        $id = $_POST['cata'];
        $api = new SoapClient('http://www.webservicex.com/globalweather.asmx?WSDL');
        $res = $api->GetCitiesByCountry(array('CountryName' => "$id"));
        var_dump($res);
    }
?> 
<form action="" method="POST">
    <select name="cata">
        <option value="Israel">Israel</option>
        <option value="Egypt">Egypt</option>
    </select>
    <br>
    <input id='sumbit' name='submit' type='submit' value='tim'>
</form>

如果此代码仍未运行,请检查您是否启用了php_soap.dll扩展。要安装此软件包,请运行sudo apt-get install php-soap,然后从php.ini文件中取消注释以下行 延长= php_soap.dll