Search code examples
phphtmlformshtml-tablehttp-post

How to POST form data from within a table to PHP


I currently have a Timesheet form I am creating for the employees at my work and I am stuck at getting the input values to post correctly. I have a database set up but right now, I can't even get the values to show in a .php page. Here is a sample from my current table:

<html>    
    <form method="POST" form action="result.php">
    <table>
        <tr><td><b>Day of Week</td><td><b>Week 1 Hours</td><td><b>Week 2 Hours</td>  <td>
        <tr><td>Monday</td><td>
        <input type="text" name="Monday" size="3" maxlength="4" value="" onkeypress="return inputLimiter(event,'Numbers')">
        <input type="checkbox" tabindex="-1" name="Stime1">Sick?<input type="checkbox" tabindex="-1" name="Vac1">Vacation?</td>
        <td><input type="text" name="Monday2" size="3" maxlength="4" value="" onkeypress="return inputLimiter(event,'Numbers')">
        <input type="checkbox" tabindex="-1" name="Stime2">Sick?<input type="checkbox" tabindex="-1" name="Vac2">Vacation?</td></tr>
    </table>
    <input type="submit" value="submit">
</html>

This pattern continues for each day of the week. And then when I try to view the results of the post I couldn't get anything to work. I resorted to trying:

<html>
<?php var_dump ($_POST);
?>
</html>

All I get is a blank page, and if I view source it just shows the php code used. It's late here so I must be too tired and missing something but I just can't figure it out.


Solution

  • I see some errors in your HTML.

    I formatted your source locally. I dont know if you did this on purpose (just copy a small part of the table) but there are some tags missing.

    I corrected your HTML, maybe you should try that. I dont know if it solves the problem. But here are some errors:

    • You never close the <b> tags in the first table row.
    • There is a table data tag (<td>) you do not close (And which is one too many) after Week 2 hours.
    • You do not close the table row tage for the first row. (<tr>)
    • You do not close the form tag.
    • The word form between the method and action in your opening form tag is incorrect. This should be removed i guess.

    <html>

    <form method="POST" action="result.php">
    <table>
        <tr>
            <td><b>Day of Week</b></td>
            <td><b>Week 1 Hours</b></td>
            <td><b>Week 2 Hours</b></td>
        </tr>
        <tr>
            <td>Monday</td>
            <td><input type="text" name="Monday" size="3" maxlength="4" value="" onkeypress="return inputLimiter(event,'Numbers')"> <input type="checkbox" tabindex="-1" name="Stime1">Sick?<input type="checkbox" tabindex="-1" name="Vac1">Vacation?</td>
            <td><input type="text" name="Monday2" size="3" maxlength="4" value="" onkeypress="return inputLimiter(event,'Numbers')"> <input type="checkbox" tabindex="-1" name="Stime2">Sick?<input type="checkbox" tabindex="-1" name="Vac2">Vacation?</td>
        </tr>
    </table>
    <input type="submit" value="submit">
    </form>
    </html>
    

    Let me know if this helps. Cheers.