如何将表中的表单数据发布到PHP [英] How to POST form data from within a table to PHP

查看:113
本文介绍了如何将表中的表单数据发布到PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的工作中为员工创建了一个时间表格式,我坚持要让输入值正确发布。我建立了一个数据库,但现在我甚至无法将这些值显示在.php页面中。以下是我当前表中的示例:

 < html> 
< form method =POSTform action =result.php>
< table>
< t>< td>< b>星期几< / td>< td>< b>第1周小时< / td>< td> / TD> < TD>
< tr>< td>星期一< / td>< td>
< input type =textname =Mondaysize =3maxlength =4value =onkeypress =return inputLimiter(event,'Numbers')>
< input type =checkboxtabindex = - 1name =Stime1> Sick?< input type =checkboxtabindex = - 1name =Vac1> Vacation? < / TD>
< td>< input type =textname =Monday2size =3maxlength =4value =onkeypress =return inputLimiter(event,'Numbers')>
< input type =checkboxtabindex = - 1name =Stime2>生病?< input type =checkboxtabindex = - 1name =Vac2> Vacation? < / TD>< / TR>
< / table>
< input type =submitvalue =submit>
< / html>

这种模式会持续一周的每一天。然后当我尝试查看帖子的结果时,我无法获得任何工作。我试图尝试:

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

我得到的只是一个空白页面,如果我查看源代码,它只显示使用的php代码。这里迟到了,所以我一定是太累了,错过了一些东西,但我无法弄清楚。

解决方案

错误在您的HTML。



我在本地格式化您的源代码。我不知道你是否真的这么做了(只是复制了表格的一小部分),但缺少一些标签。



我更正了你的HTML,也许你应该尝试那。我不知道它是否解决了这个问题。但这里有一些错误:


  • 您从不关闭< b> 标签在第一个表格行。
  • 有一个表格数据标签(< td>)您不关闭一个太多了)。

  • 您不关闭第一行的表行索引。 (< tr>)

  • 您不关闭表单标记。表单标签中的方法和动作之间的单词形式不正确。这应该被删除我猜。



< html>

 < form method =POSTaction =result.php> 
< table>
< tr>
< td>< b>星期几< / b>< / td>
< td>< b>第1周小时< / b>< / td>
< td>< b>第2周小时< / b>< / td>
< / tr>
< tr>
< td>星期一< / td>
< td>< input type =textname =Mondaysize =3maxlength =4value =onkeypress =return inputLimiter(event,'Numbers')> < input type =checkboxtabindex = - 1name =Stime1> Sick?< input type =checkboxtabindex = - 1name =Vac1> Vacation?< / td> ;
< td>< input type =textname =Monday2size =3maxlength =4value =onkeypress =return inputLimiter(event,'Numbers')> < input type =checkboxtabindex = - 1name =Stime2> Sick?< input type =checkboxtabindex = - 1name =Vac2> Vacation?< / td> ;
< / tr>
< / table>
< input type =submitvalue =submit>
< / form>
< / html>

让我知道这是否有帮助。
干杯。


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.

解决方案

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.

这篇关于如何将表中的表单数据发布到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆