如何将$ _POST变量传递到同一页面

时间:2014-05-02 20:15:38

标签: php

我没有看到此代码的HTML部分中的echo结果,我尝试回显$ _POST变量。我填写表格。单击“提交”但表单下没有任何内容,但它应显示两个字符串。

这是一个单页表单,它将根据表单字段中提供的值从我在此代码中构建的URL中提取XML数据。

<!DOCTYPE html>
<?php
    if(isset($_GET['company']) and isset($_GET['from']) and isset($_GET['to']) and isset($_GET['submit'])){
        $parameters = array(
            'company' => $_GET['company'],
            'from' => $_GET['from'],
            'to' => $_GET['to']
        );
        // create condition
        $condition = "date_entered > '" . $parameters['from'] . "' && date_entered < '" . $parameters['to'] . "' && company_name = '" . $parameters['company'] . "'";
        $url = "www.abc.com/c=" . $condition;
        echo '<p>'.$condition.'</p>';
        echo '<p>'.$url.'</p>';
        $_GET['condition'] = $condition;
        $_GET['url'] = $url;
    }
?>
<html>
    <head>
        <title>Reports v. 0.0.0.1</title>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css">
        <script>
            $(function() {
            $( "#from" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            onClose: function( selectedDate ) {
            $( "#to" ).datepicker( "option", "minDate", selectedDate );
            }
            });
            $( "#to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            onClose: function( selectedDate ) {
            $( "#from" ).datepicker( "option", "maxDate", selectedDate );
            }
            });
            });
        </script>
    </head>
    <body>
        <form autocomplete="on" method="GET">
            Company: <input id="company" name="company" type="text" value="" /><br />
            <fieldset width="0px">
            <legend>Date Range</legend>
            <label for="from">From</label>
            <input type="text" id="from" name="from"><br />
            <label for="to">To</label>
            <input type="text" id="to" name="to"><br />
            </fieldset>
            <input type="submit" />
        </form>
        <?php
            if(isset($_GET['condition']) and isset($_GET['url'])){
                echo $_GET['condition'];
                echo '<br />';
                echo $_GET['url'];
            }
        ?>
    </body>
</html> 

1 个答案:

答案 0 :(得分:0)

转储全局$ _GET,将其与您正在检查的内容进行比较。这应该会有所帮助。