我一直在做一个关于使用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
答案 0 :(得分:0)
如果您使用两个名称相同的字段名称&#34; content_txt&#34;发布它。
或者当ajax数据在ajax字段上更改它的名称时。