开发者

PHP Post Variable Problem

开发者 https://www.devze.com 2023-03-11 15:23 出处:网络
It\'s been a little while with PHP, so please excuse my ignorance. I have this web page: <?php mysql_connect (\"localhost\", \"user\", \"pass\");

It's been a little while with PHP, so please excuse my ignorance. I have this web page:

<?php
mysql_connect ("localhost", "user", "pass");
mysql_select_db ("expiration");

if (isset ($_REQUEST['new_expire']) && $_REQUEST['new_expire'] != "") {
    $insert_query = "INSERT INTO files (path, expires) VALUES ('";
    $insert_query .= $_REQUEST['new_path'];
    $insert_query .= "', '";
    $insert_query .= $_REQUEST['new_expire'];
    $insert_query .= "');";
    mysql_query ($insert_query);
}
?>
<html>
<head></head>
<body>
    <?php echo print_r $_REQUEST; ?>
    <form action="index.php" method="POST">
        <p>Add 开发者_高级运维New Expiration</p>
        <table>
            <tr>
                <td align="right">
                    Select File:
                </td>
                <td>
                    <select id="new_path">
                        <?php $options = buildOptions (); echo $options; ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">
                    MySQL Expire Time:
                </td>
                <td>
                    <input type="text" id="new_expire" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" value="Save" />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
<?php
mysql_close ();
?>

When I load the page, the result of the print_r is an empty array. When I submit the form, it's still empty. I get no new record in the database. Any ideas?


Change all the places you have id to name, for example:

<input type="text" id="new_expire" /> --> <input type="text" name="new_expire" />

The _REQUEST (either _POST or _GET) is only from input elements with a name

0

精彩评论

暂无评论...
验证码 换一张
取 消