【发布时间】:2010-07-25 06:58:48
【问题描述】:
我正在尝试将序列化的表单发布到 sumbit.php 文件,然后将插入 MySQL 数据库;然而,最后一个隐藏的输入并没有被插入到数据库中,尽管其余的都是。
这里有一些 sn-p 示例,说明到目前为止我所得到的不起作用:
HTML
<form method="post" action="" >
<label for="name" class="overlay"><span>Name...</span></label>
<input class="input-text" type="text" name="name" id="name" />
<label for="email" class="overlay"><span>Email...</span></label>
<input type="text" class="input-text" name="email" id="email"/>
<label for="website" class="overlay"><span>Website...</span></label>
<input type="text" class="input-text" name="website" id="website"/>
<label id="body-label" for="body" class="overlay"><span>Comment it up...</span></label>
<textarea class="input-text" name="body" id="body" cols="20" rows="5"></textarea>
<input type="hidden" name="parentid" id="parentid" value="0" />
<input type="submit" value="Comment" name="submit" id="comment-submit" />
</span>
</form>
Javascript
$('form.').submit(function(event) {
$.post('submit.php',$(this).serialize(),function(msg){
// form inputs consist of 5 values total: name, email, website, text, and a hidden input that has the value of an integer
}
});
PHP (submit.php)
$arr = array();
mysql_query(" INSERT INTO comments(name,email,website,body,parentid)
VALUES (
'".$arr['name']."',
'".$arr['email']."',
'".$arr['website']."',
'".$arr['body']."',
'".$arr['parentid']."'
)");
【问题讨论】:
-
serialize()文档页面上的 cmets 似乎表明其他人在序列化隐藏字段方面也存在问题:api.jquery.com/serialize -
希望小鲍比不要来访 - xkcd.com/327
标签: php mysql forms insert serialization