【问题标题】:Adding additional form post fields to a mysql insert script向 mysql 插入脚本添加额外的表单发布字段
【发布时间】: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


    【解决方案1】:

    如果您使用两个表单,只是命名相同的字段名称“content_txt”并发布它。

    或者当你 ajax 数据在 ajax 字段上更改它的名称时。

    【讨论】:

    • 您好,我没有看到有人回答了这个问题,但是我有一个新问题,其中包含有关此问题的更多信息,但是给出的两个答案都不起作用。这是它的链接stackoverflow.com/questions/21123567/…
    猜你喜欢
    • 2018-10-10
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2015-08-26
    • 2010-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多