0

//错误:信息被附加但没有被替换。

<form action="testme.php" method="get">
    <p>
        <input name="search" type="text" value="">
        <input type="submit" name="button" id="button" value="Submit">
    </p>

    <h3>Filter Results</h3>
<p><a href="testme.php?filter='Action'<?php if (isset($_GET['search']) && !empty($_GET['search'])) {echo '&search='.$_GET['search'];}
?>">Action</a></p>


<p><a href="testme.php?filter='Comedy'<?php if (isset($_GET['search']) && !empty($_GET['search'])) {echo '&search='.$_GET['search'];}
?>">Comedy</a></p>

</form>


<?php

if (isset($_GET['button']) && isset($_GET['search']) != '') {
    echo $_GET['search'];

}
elseif (isset($_GET['filter']) == "Action" && isset($_GET['search']) != '') {
    echo "Action " . $_GET['search'];

}

elseif (isset($_GET['filter']) == "Action" && isset($_GET['search']) == '') {

    echo " No action Involved ";
}

if (isset($_GET['filter']) == "Comedy" && isset($_GET['search']) == '') {

    echo " No Comedy Involved";
}

//当我点击任何一个链接时,我得到:不涉及任何动作不涉及喜剧。但我只想展示一个?>

4

4 回答 4

0

这是因为它$_GET['search']是未定义的

正确的代码:

 <form action="index.php" method="get">
    <p>
        <input name="search" type="text" value="">
        <input type="submit" name="button" id="button" value="Submit">
    </p>



    <h3>Filter Results</h3>
    <p>
    <a href="index.php?filter='Action'&search=<?php if (isset($_GET['search'])) { echo $_GET['search']; } ?>">Action</a>
    </p>
</form>


    <?php

if (isset($_GET['button']) && isset($_GET['search']) != '') {
    echo $_GET['search'];

}
elseif (isset($_GET['filter']) == "Action" && isset($_GET['search']) != '') {
    echo "Action " . $_GET['search'];

}
//the logic is to click on the action without filling in the search form and get it to work

elseif (isset($_GET['filter']) == "Action" && empty($_GET['search'])) {

    echo "No action Involved";
}
?>
于 2013-07-25T19:50:53.020 回答
0

PHP 在页面发送到浏览器之前运行,而不是之后。因此,当第一次发送页面时,构建链接的代码还没有任何价值。

于 2013-07-25T19:51:45.223 回答
0

你必须先定义 GET['search'] 然后声明这个 <a href="index.php?filter='Action'&search=<?php echo $_GET['search']

于 2013-07-25T19:53:40.813 回答
0

这应该工作

<a href="index.php?filter='Action'&search=<?=@$_GET['search']; ?>>
于 2013-07-25T19:58:22.417 回答