-1

我想在我的表单上有一个隐藏字段,我将通过 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>

提交.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> ?>"/>
4

1 回答 1

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>" ?>"/>
于 2012-11-17T12:42:37.107 回答