0

我只是想让这个简单的 php 文件工作:

<html>
<head>
    <title>Aarons Editor</title>
</head>
<body>
<form action="index.php" method="get">
    <select name="page">
        <option value="default"> </option>
        <option value="file">File</option>
    </select>
    <input type="submit">
</form>

<?php
        if (page == $_GET['file']){
            echo "<h1>File</h1>";

        }

        else {
            echo "<h1>not file</h1>";
        }
    }
    ?>


    </body>
</html>

另外,我不知道如何在表单中调用特定函数。

4

2 回答 2

0

试试这个,好先生

<html>
<head>
    <title>Aarons Editor</title>
</head>
<body>
<form method="post">
    <select name="page">
        <option value="default"> </option>
        <option value="file">File</option>
    </select>
    <input type="submit" name="gog">
</form>

<?php
        if($_POST['gog']){
        if ($_POST['page'] == 'file'){
            echo "<h1>File</h1>";

        }

        else {
            echo "<h1>not file</h1>";
        }
    }
    ?>


    </body>
</html>
于 2013-08-31T23:28:53.997 回答
0

我认为您正在尝试执行以下操作

<html>
    <head>
        <title>Aarons Editor</title>
    </head>
    <body>
        <!-- method="get" makes a form write attributes to url
        ie. ?page=file or ?page=default
        -->
        <form action="index.php" method="get">
            <select name="page">
                <option value="default"> </option>
                <option value="file">File</option>
            </select>
            <input type="submit">
        </form>

        <?php
            // this checks if there is a parameter ?page set in url
            if (isset($_GET['page'])) {
                // this assigns a <select> value to variable $page
                $page = $_GET['page'];
                // this checks if selected value was 'file'
                if ($page === "file") {
                   echo '<h1>'.$page.'</h1>';
                } else { // this is if not
                    echo '<h1>not file</h1>';
                }
            }
        ?>

    </body>
</html>
于 2013-08-31T23:30:10.373 回答