Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php不会将变量传递给php rss函数_Php - Fatal编程技术网

php不会将变量传递给php rss函数

php不会将变量传递给php rss函数,php,Php,我有 我有一个名为getPosts的php函数,我想通过表单将url发送到该函数: <form action="#" method = "post"> <input type="hidden" name="sub" value="1" /> <select name="url" id="url"> <option value="http://www.chess.com/rss/articles">chess.com</option>

我有

我有一个名为getPosts的php函数,我想通过表单将url发送到该函数:

<form action="#" method = "post"> 
<input type="hidden" name="sub" value="1" /> 
<select name="url" id="url">
<option value="http://www.chess.com/rss/articles">chess.com</option>
<option value="http://chesscafe.com/feed/">Chess Cafe</option>
<option value="http://www.chessdom.com/rss">Chessdom</option>
<option value="http://chess-news.ru/rss-eng">Chess-news</option>

</select>
</form>
出于某种原因,下面的php代码没有获取所选的选项并将其传递给函数。为什么呢

<?php
$sub = intval( $_POST["sub"]);  
if ($sub == 1){ 
$url= $_POST["url"];
}
else{
$url = "http://www.theweekinchess.com/twic-rss-feed"; 
}

getPosts($url); ?>

这是因为没有提交按钮。如果您想在更改时自动提交表单,您需要执行以下操作

<form name="myform" action="#" method = "post">
<select name="url" id="url" onchange="document.forms['myform'].submit()">
美元POST的var_转储说明了什么?
<?php

if(isset($_POST["url")){
$url = $_POST["url"];
}
else{
$url = "http://www.theweekinchess.com/twic-rss-feed"; 
}

getPosts($url); ?>