嗨我有三个表单和一个提交按钮,它位于所有三个表单之外,我想将所有三个表单的值保存到mysql数据库中,任何人都可以帮我展示如何完成它我正在使用jquery提交表单值 这是我的jquery
<script>
$(document).ready(function() {
$("#submit").click(function(event) {
alert('send 1st form');
$.post($("#form1").attr("action"), $("#form1").serialize(),
function() {
alert('send 2nd form');
$.post($("#form2").attr("action"), $("#form2").serialize(),
function() {
alert('send 3th form');
$.post($("#form3").attr("action"), $("#form3").serialize(),
function() {
alert('Both forms submitted');
});
});
});
event.preventDefault();
});
});
</script>
因为我之前发布了一个查询,这有助于我提交表单,现在我想将值保存到我的数据库中
她是我的PHP代码
if(isset($_POST["submit"])){
$gen1 = mysql_query("SELECT MAX(accode) AS maxcode FROM quotmain LIMIT 0,1 ") or die(mysql_error());
if (mysql_num_rows($gen1) > 0) {
$vvouch = mysql_fetch_assoc($gen1);
$qvouch = $vvouch["maxcode"] + 1;
} else{
$qvouch = '1';
}
$a = 1;
$vouchdt = mydt($_POST["vouchdt"]);
$name = $_POST["cmbparty"];
$refno = $_POST["refno"];
$attn = $_POST["attn"];
$subj = $_POST["subject"];
$msg = $_POST["messsage"];
$rem = $_POST["rem"];
$count = $_POST["items"];
$h = $_POST["h"];
$status = $_POST["cmbstatus"];
mysql_query("DELETE FROM quotdtl WHERE vouchno='$qvouch'") or die(mysql_error());
for ($i = 1; $i <= $count; $i++) {
$ord = $_POST['ord_' . $i];
$srno = $_POST['srno_' . $i];
$descrip = $_POST['descrip_' . $i];
$unit = $_POST['unit_' . $i];
$rate = $_POST['rate_' . $i];
mysql_query("INSERT INTO `quotdtl`(vouchno, orderby, srno, `descrip`, unit, rate)
VALUES('$qvouch', '$ord', '$srno', '$descrip', '$unit', '$rate')") or die(mysql_error());
}
mysql_query("DELETE FROM quotnotes WHERE vouchno='$qvouch'") or die(mysql_error());
for ($i = 1; $i <= $h; $i++) {
$notes = $_POST['notes' . $i];
mysql_query("INSERT INTO `quotnotes`(vouchno, `notes`)
VALUES('$qvouch', '$notes')") or die(mysql_error());
}
if ($addflag == 1) {
mysql_query("INSERT INTO `quotmain`(vouchno, `vouchdt`, `name`, refno, `attn`, `subject`, `message`, `rem1`, `status`, `username`)
VALUES($qvouch, '$vouchdt', '$name', '$refno', '$attn', '$subj', '$msg', '$rem', '$status','$_SESSION[username]')") or die(mysql_error());
insmess();
header("refresh: 1; quotation.php?mode=true");
} else {
$mvouch = $_POST["vouch"];
mysql_query("UPDATE `quotmain` SET `vouchdt`='$vouchdt', `name`='$name', refno='$refno', `attn`='$attn', `subject`='$subj',
`message`='$msg', `rem1`='$rem', `username`='$_SESSION[username]' WHERE vouchno = '$mvouch' ") or die(mysql_error());
updmess();
header("refresh: 1; menu.php?action=quotation");
}
}
答案 0 :(得分:0)
简短的回答:你不能。您的浏览器将始终只发送一个表单。
答案很长:您可以在另一个表单()中为一个表单的每个输入元素创建一个等价物,并在onSubmit中将隐藏字段的值设置为非隐藏字段的值:
onsumbmit="$('#foobar_hidden').val( $('#foobar').val() ); return 1";
答案 1 :(得分:0)
尝试将提交按钮的HTML更改为
<button type="button" id="submit">Submit</button>
这会阻止您的浏览器在点击提交按钮时尝试发送单个表单,并且只会执行您在JavaScript中放置的内容。