是因为if声明吗?

时间:2015-02-17 11:00:57

标签: php html if-statement

这段代码不会回响,为什么??

if (isset( $_post['text']) &&isset( $_post['search for']) && isset($_post['Replace'])){
  echo $text= $_post['text'];
  echo $replace= $_post['replace'];
  echo $search= $_post['searchfor'];
  echo $text;
}
?>
<form action='index.php' method ='get'>
  <textarea name='text'  rows=6 cols=30 > </textarea><br><br>
   Search for:<br>
   <input type ='text' name='search for'><br><br>
   Replace with:<br>
   <input type='text' name='replace'><br><br>
   <input type='submit' value='Find & Replace'>``
</form>

5 个答案:

答案 0 :(得分:1)

您尝试将$_POSTform设置为method的{​​{1}}元素合并。

GET元素form属性更改为method,或将POST更改为$_POST

解决方案1 ​​

$_GET
<form action='index.php' method='post'>

解决方案2

if (isset( $_POST['text']) && isset( $_POST['search for']) && isset($_POST['replace']))
<form action='index.php' method='get'>

答案 1 :(得分:0)

您应该使用$_POST代替$_post。在form您将method指定为get,请将其替换为post

最终的代码是..

 if (isset( $_POST['text']) &&isset( $_POST['search for']) && isset($_POST['Replace'])){
      echo $text= $_post['text'];
      echo $replace= $_post['replace'];
      echo $search= $_post['search for'];
      echo $text;
    }
    ?>
    <form action='index.php' method ='POST'>
      <textarea name='text'  rows=6 cols=30 > </textarea><br><br>
       Search for:<br>
       <input type ='text' name='search for'><br><br>
       Replace with:<br>
       <input type='text' name='replace'><br><br>
       <input type='submit' value='Find & Replace'>``
    </form>

答案 2 :(得分:0)

$_post['search for']中有一个空格,但您稍后会问$_post['searchfor']的代码

答案 3 :(得分:0)

请使用$_POST代替$_post

字段名称中不应包含空格。所以请改用search_for    search for

if (isset( $_POST['text']) && isset( $_POST['search_for']) && isset($_POST['replace'])){
    echo $text= $_POST['text'];
    echo $replace= $_POST['replace'];
    echo $search= $_POST['search_for'];
}
<form action='index.php' method ='POST'>
  <textarea name='text'  rows=6 cols=30 > </textarea><br><br>
   Search for:<br>
   <input type ='text' name='search_for'><br><br>
   Replace with:<br>
   <input type='text' name='replace'><br><br>
   <input type='submit' value='Find & Replace'>``
</form>

答案 4 :(得分:0)

您在输入框和php中的名称不同,这是您的解决方案

if (isset( $_POST['text']) && isset( $_POST['search for']) && isset($_POST['replace'])){
    echo $text= $_POST['text'];
    echo $replace= $_POST['replace'];
    echo $search= $_POST['search for'];
}
<form action='index.php' method ='POST'>
  <textarea name='text'  rows=6 cols=30 > </textarea><br><br>
   Search for:<br>
   <input type ='text' name='search for'><br><br>
   Replace with:<br>
   <input type='text' name='replace'><br><br>
   <input type='submit' value='Find & Replace'>

你也可以通过Get方法

来做到这一点