2012-11-17 106 views
-1

我想在我的表单上有一个隐藏字段,我将通过php提交给MySql数据库。Php隐藏字段表单不提交到MySql数据库

形式

<form id="addCommentForm" method="post" action=""> 
<dl> 
<dt><label class="formComment" for="body">Message *</label></dt> 
<dd><textarea class="inputbox" name="body" id="body"></textarea></dd> 
<dt><label class="formName" for="name">Name *</label></dt> 
<dd><input class="inputbox" type="text" name="name" id="name" /></dd> 
<input type="hidden" name="post_id" id="post_id" value="tree"/> 
</dl> 
<input type="submit" class="button" id="submit" value="Submit" /> 
</form> 

submit.php

mysql_query(" INSERT INTO comments(post_id,name,url,email,body) 
       VALUES (
        '".$arr['post_id']."', 
        '".$arr['name']."', 
        '".$arr['body']."' 
       )"); 

$arr['dt'] = date('r',time()); 
$arr['id'] = mysql_insert_id(); 

当我提出这个到MySQL,仅从名字和身体(消息)的值会出现在我的MySQL数据库,但隐藏的值不会通过。

这里我的错误是什么?

另外我想要隐藏的值作为页面的标题,这是在h2标签下。我尝试过这样的事情(这很糟糕,我知道)。

<input type="hidden" name="post_id" id="post_id" value="<?php echo <h2></h2> ?>"/> 
+1

请回覆一些php/mysql错误 – vlcekmi3

+0

print_r($ _ POST)的输出是什么; ?? – sikas

回答

1
<input type="hidden" name="post_id" id="post_id" value="<?php echo "<h2></h2>" ?>"/> 

您回应

为什么action=""空后没有行情?

<form id="addCommentForm" method="post" action=""> 
<dl> 
<dt><label class="formComment" for="body">Message *</label></dt> 
<dd><textarea class="inputbox" name="body" id="body"></textarea></dd> 
<dt><label class="formName" for="name">Name *</label></dt> 
<dd><input class="inputbox" type="text" name="name" id="name" /></dd> 
<input type="hidden" name="post_id" id="post_id" value="tree"/> 
</dl> 
<input type="submit" class="button" id="submit" value="Submit" /> 
</form> 
    <input type="hidden" name="post_id" id="post_id" value="<?php echo "<h2></h2>" ?>"/> 
+4

如果您希望表单提交到同一页面,那么'action'可以为空。 –