2012-11-17 107 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'可以爲空。 –