[英]Adding additional form post fields to a mysql insert script
我一直在做關於使用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
如果您使用兩個僅命名為相同字段名稱“ content_txt”的表單並將其發布。
或者當您使用ajax數據更改ajax字段上的名稱時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.