【发布时间】:2014-02-02 03:37:04
【问题描述】:
我一直在做一个关于使用 Ajax 发布到数据库的教程,现在我可以使用 1 个表单字段,但我想学习如何让它使用 2 个表单字段。
我正在处理的表单字段名为content_txt,它被插入到add_delete_record(content)。第二种形式名为balance_txt,也将插入到与content_txt 相同的表中。
这是我试图弄清楚如何使用额外的表单字段进行更新的代码块。我在其中添加了注释来解释我使用每件东西的目的以及我想要做什么:
if(isset($_POST["content_txt"]) && strlen($_POST["content_txt"])>0)
{ //checks $_POST["content_txt"] is not empty, but I am not sure how to add the other field into this
$contentToSave = filter_var($_POST["content_txt"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
//using this to strip stuff from the post, but I am not sure how I should added the other form field to this, should I create another variable line or can I add it to this.
// Insert sanitize string in record and I think I have it correct, except if I need to add a variable following content
if(mysql_query("INSERT INTO add_delete_record(`content`,`balance`) VALUES('".$contentToSave."')"))
{
//This returns the results back to the page, do I need to have a duplicate section for the additional record or will this work like a loop.
$my_id = mysql_insert_id(); //Get ID of last inserted row from MySQL
echo '<li id="item_'.$my_id.'">';
echo '<div class="del_wrapper"><a href="#" class="del_button" id="del-'.$my_id.'">';
echo '<img src="images/icon_del.gif" border="0" />';
echo '</a></div>';
echo $contentToSave.'</li>';
mysql_close($connecDB); //close db connection
【问题讨论】:
标签: php jquery mysql ajax forms