0

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?

1
  • 1
    print_r() by default already outputs its results directly, so there's no need to add echo, as that'd just spit out the value returned by print_r, which is TRUE. Of course, since PHP's hallmark is (in)consistence, if you do print_r(true) it returns that dump and THEN your echo would work. Commented Jun 6, 2011 at 18:22

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

@Raynos, game it? what does that mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.