首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提交按钮更新一个表并将详细信息发送到另一个表

提交按钮更新一个表并将详细信息发送到另一个表
EN

Stack Overflow用户
提问于 2014-08-19 16:30:25
回答 2查看 292关注 0票数 0

我有一个修改表'wp_postmeta‘的元内容的表单。我试图找出一种方法,使表单中的操作也插入到另一个表中。

这个是可能的吗?这就是我所拥有的,数据没有插入到事务表中。

当前表格提交按钮div:

代码语言:javascript
复制
<div class='inventory-management-form-item-holders inventory-management-submit-holder'>
    <input type="submit" name="submit" value="SUBMIT">
</div>

“库存-管理-提交”js部分:

代码语言:javascript
复制
// submit form
jQuery("#submit").click(function(){
    // Change thw loading Gif url 
    jQuery('#the-results-holder').html("<img src='/wp-content/plugins/mcs-inventory-management/assets/images/loading_icon.gif' />");
    jQuery.ajax({
        type: "POST",
        data: {'im-product-id': theProductId, 'status-quantity': jQuery('#status-quantity').val(), 'status-action': jQuery('#im-action-box').val(), 'status-location': jQuery('#status-location').val(), 'status-move-location': jQuery('#status-move-location').val()},
        dataType: "json",
        url: "/inventory-management-process/",
        processData: true,
        success: function(data) {
            jQuery('#the-results-holder').html(""); 
            jQuery('#status-stock').val(data.stock);
            jQuery('#status-res').val(data.res);
            jQuery('#status-prepro').val(data.prepro);
            jQuery('#status-clean').val(data.clean);
            jQuery('#status-quantity').val("0");
        },
        error: function (xhr, ajaxOptions, thrownError) {
            jQuery('#the-results-holder').html(""); 
            jQuery('#the-results-holder-error').html("There has been an error!"); 
        }
    });
    return false;
});

--这是我尝试在事务表?中执行表单插入的地方。

代码语言:javascript
复制
<form name='inventory-management' id='inventory-management-form' method="POST" action='<?php $transaction ?>'>


<?php
$product= $_POST['part-number'];
$action= $_POST['status-action'];
$from_location= $_POST['status-location'];
$to_location= $_POST['status-move-location'];
$qty= $_POST['status-quantity'];


if(isset($_POST['submit']))
{
 $transaction = "INSERT INTO mcs_inventory_transactions (id,product,action,from_location,to_location,qty) VALUES ('','$product','$action','$from_location','$to_location','$qty')";
 $result = mysql_query($transaction);
}
?>
EN

回答 2

Stack Overflow用户

发布于 2014-08-19 16:41:44

把你的js改为

代码语言:javascript
复制
  JS
// submit form

    jQuery("#inventory-management-submit").click(function(){
        // Change thw loading Gif url 
        jQuery('#the-results-holder').html("<img src='/wp-content/plugins/mcs-inventory-management/assets/images/loading_icon.gif' />");
        jQuery.ajax({
            type: "POST",
            data: {'im-product-id': theProductId, 'status-quantity': jQuery('#status-quantity').val(), 'status-action': jQuery('#im-action-box').val(), 'status-location': jQuery('#status-location').val(), 'status-move-location': jQuery('#status-move-location').val(),submit: "test"},
            dataType: "json",
            url: "/inventory-management-process/",
            processData: true,
            success: function(data) {
                jQuery('#the-results-holder').html(""); 
                jQuery('#status-stock').val(data.stock);
                jQuery('#status-res').val(data.res);
                jQuery('#status-prepro').val(data.prepro);
                jQuery('#status-clean').val(data.clean);
                jQuery('#status-quantity').val("0");
            },
            error: function (xhr, ajaxOptions, thrownError) {
                jQuery('#the-results-holder').html(""); 
                jQuery('#the-results-holder-error').html("There has been an error!"); 
            }
        });
        return false;
    });

希望这对你有帮助

票数 0
EN

Stack Overflow用户

发布于 2014-08-19 16:40:36

这是错误的:

代码语言:javascript
复制
$transaction= if(isset($_POST['submit']))

应该是

代码语言:javascript
复制
if(isset($_POST['submit']))
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25388535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档