Php 提交按钮有两个动作
我有一个表单修改了“wp_postemta”表的元内容。我正试图找到一种将表单结果添加到另一个表(事务)的方法 我有php设置,如果我从提交输入部分删除“id”值,它就会工作。在包含ID的情况下,表单修改wp_Posteta,但不向“transactions”表发送任何数据。如果不包括ID,则相反。有什么建议吗 表单提交按钮:Php 提交按钮有两个动作,php,jquery,mysql,Php,Jquery,Mysql,我有一个表单修改了“wp_postemta”表的元内容。我正试图找到一种将表单结果添加到另一个表(事务)的方法 我有php设置,如果我从提交输入部分删除“id”值,它就会工作。在包含ID的情况下,表单修改wp_Posteta,但不向“transactions”表发送任何数据。如果不包括ID,则相反。有什么建议吗 表单提交按钮: <div class='inventory-management-form-item-holders inventory-management-submit-hol
<div class='inventory-management-form-item-holders inventory-management-submit-holder'>
<input type="submit" name="submit" value="SUBMIT" id="im-submit">
</div>
// submit form
jQuery("#im-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;
});
“im提交”js部分:
<div class='inventory-management-form-item-holders inventory-management-submit-holder'>
<input type="submit" name="submit" value="SUBMIT" id="im-submit">
</div>
// submit form
jQuery("#im-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;
});
//提交表单
jQuery(“#im submit”)。单击(函数(){
//更改加载Gif url的方式
jQuery(“#结果持有者”).html(“”);
jQuery.ajax({
类型:“POST”,
数据:{'im-product-id':产品id,'status quantity':jQuery('#status quantity').val(),'status action':jQuery('#im action box').val(),'status location':jQuery('#status move location').val(),'status move location':jQuery('#status move location').val(),
数据类型:“json”,
url:“/inventory management process/”,
processData:对,
成功:功能(数据){
jQuery(“#结果持有者”).html(“”);
jQuery('#status stock').val(data.stock);
jQuery('#status res').val(data.res);
jQuery('#status prepo').val(data.prepo);
jQuery('#status clean').val(data.clean);
jQuery('#status quantity').val(“0”);
},
错误:函数(xhr、ajaxOptions、thrownError){
jQuery(“#结果持有者”).html(“”);
jQuery(“#结果持有者错误”).html(“出现了错误!”);
}
});
返回false;
});
对“事务”表使用插入查询的PHP
<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 transactions (id,product,action,from_location,to_location,qty) VALUES ('','$product','$action','$from_location','$to_location','$qty')";
$result = mysql_query($transaction);
}
?>
如果从“提交输入”部分删除“id”值,则该操作有效,因为表单是通过浏览器而不是js代码提交的,然后提交
值位于$\u POST
中
要使jQuery代码正常工作,您需要在帖子中添加submit
值,如下所示:
// submit form
jQuery("#im-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' />");
var ajax_config = {
type: "POST",
data: {
'submit': 'submit',
'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!");
}
};
jQuery.ajax(ajax_config);//jajax # 1
//change the url
ajax_config.url = jQuery('#inventory-management-form').attr("action");
jQuery.ajax(ajax_config);//jajax # 2
return false;
});
如果由于jQuery(“#im submit”)
而删除表单提交的ID而不是jQuery ajax,那么将更新添加到/inventory management process/php中-action=''>做什么?这不应该是action=''>,只是为了澄清一下,您需要在一个表上按id进行更新,然后在另一个表上进行插入吗?为什么不使用两个独立的语句一个接一个地运行呢?正确,没有ID,jQuery就不会运行。是的,我正在尝试更新和插入。我要复制哪个声明。谢谢你的建议。我添加了'submit':'submit',并尝试使用id='im-submit'和不使用id='im-submit'都不起作用。我假设我离开了jQuery(“#im submit”)。单击(函数(){原样?如果要使用jQuery,请不要从html中删除ID,进行我建议的更改,然后重试。还尝试了“提交”:jQuery(“#im submit”).val(),…这也没什么好运气。你是否使用了像Firebug这样的调试工具栏?你能在html提交按钮中检查你提交表单的位置吗?是否在同一个位置?在你发布的代码中,你有action=''
,这不应该是@mplungjan建议的action='>
“/inventory management process/”,
提交的正确url应发送到哪里?带id:它更新wp_Posteta表,但不带id:它将表单结果添加到事务表不确定是否需要回显,因为当id从提交中排除时,查询会运行。url正确