Javascript 表中的多个内联插入
我试图在其他表中插入用于开票的 我曾尝试创建insert函数,但它并没有插入到表中,每次我单击页面甚至输入标记时,它总是显示localhost,但为空 表格如下:Javascript 表中的多个内联插入,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,我试图在其他表中插入用于开票的 我曾尝试创建insert函数,但它并没有插入到表中,每次我单击页面甚至输入标记时,它总是显示localhost,但为空 表格如下: <form class="form-vertical" name="save" id="save" enctype="multipart/form-data" method="post" accept-charset="utf-8"> <div class="form-group ro
<form class="form-vertical" name="save" id="save" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="form-group row">
<label for="inv_date" >Date</label>
<div class="col-sm-8">
<input type="date" class="form-control" autocomplete="off" id="inv_date" name="inv_date" required>
</div>
</div>
<div class="form-group row">
<label for="inv_num" >Inv Number</label>
<div class="col-sm-8">
<input type="number" class="form-control" autocomplete="off" id="inv_num" name="inv_num" required>
</div>
</div>
<div class="table-responsive">
<table class="table table-bordered" id="crud_table">
<tr>
<th width="30%">Item Name</th>
<th width="10%">Item Code</th>
<th width="45%">Description</th>
<th width="10%">Price</th>
<th width="5%"></th>
</tr>
<tr>
<td contenteditable="true" class="item_name"></td>
<td contenteditable="true" class="item_code"></td>
<td contenteditable="true" class="item_desc"></td>
<td contenteditable="true" class="item_price"></td>
<td></td>
</tr>
</table>
<div align="right">
<button type="button" name="add" id="add" class="btn btn-success btn-xs">+</button>
</div>
<div align="center">
<button type="submit" name="save" id="save" class="btn btn-info">Save</button>
</div>
</div>
</form>
</div>
<script>
$(document).ready(function(){
var count = 1;
$('#add').click(function(){
count = count + 1;
var html_code = "<tr id='row"+count+"'>";
html_code += "<td contenteditable='true' class='item_name'></td>";
html_code += "<td contenteditable='true' class='item_code'></td>";
html_code += "<td contenteditable='true' class='item_desc'></td>";
html_code += "<td contenteditable='true' class='item_price' ></td>";
html_code += "<td><button type='button' name='remove' data-row='row"+count+"' class='btn btn-danger btn-xs remove'>-</button></td>";
html_code += "</tr>";
$('#crud_table').append(html_code);
});
$(document).on('click', '.remove', function(){
var delete_row = $(this).data("row");
$('#' + delete_row).remove();
});
$('#save').click(function(){
var item_name = [];
var item_code = [];
var item_desc = [];
var item_price = [];
$('.item_name').each(function(){
item_name.push($(this).text());
});
$('.item_code').each(function(){
item_code.push($(this).text());
});
$('.item_desc').each(function(){
item_desc.push($(this).text());
});
$('.item_price').each(function(){
item_price.push($(this).text());
});
$.ajax({
url:"insert.php",
method:"POST",
data:{item_name:item_name,item_code:item_code, item_desc:item_desc, item_price:item_price},
success:function(data){
alert(data);
$("td[contentEditable='true']").text("");
for(var i=2; i<= count; i++)
{
$('tr#'+i+'').remove();
}
}
});
});
});
</script>
日期
库存编号
项目名称
项目代码
描述
价格
+
拯救
$(文档).ready(函数(){
var计数=1;
$('#添加')。单击(函数(){
计数=计数+1;
var html_code=“”;
html_代码+=“”;
html_代码+=“”;
html_代码+=“”;
html_代码+=“”;
html_代码+=“-”;
html_代码+=“”;
$(“#crud_表”).append(html_代码);
});
$(文档)。在('单击','删除',函数()上){
var delete_row=$(this).data(“row”);
$(“#”+删除行)。删除();
});
$(“#保存”)。单击(函数(){
var项目名称=[];
var项目_代码=[];
var项目描述=[];
var项目价格=[];
$('.item_name')。每个(函数(){
item_name.push($(this.text());
});
$('.item_code')。每个(函数(){
item_code.push($(this.text());
});
$('.item_desc')。每个(函数(){
项目描述推送($(this.text());
});
$('.item_price')。每个(函数(){
商品价格推送($(this.text());
});
$.ajax({
url:“insert.php”,
方法:“张贴”,
数据:{item_name:item_name,item_code:item_code,item_desc:item_desc,item_price:item_price},
成功:功能(数据){
警报(数据);
$(“td[contentEditable='true']);
对于(变量i=2;i而不是if(isset($\u POST['item\u name']))
我尝试了不同的方法,比如:
if ($result) {
$j = 0;
$count = sizeof($_POST['po_qty']); // ive use the sizeof() to get the count of the rows
// Use insert_id property
$po_trans_id = $link->insert_id;
$user = $_SESSION["username"];
for ($j = 0; $j < $count; $j++) {
$query = "INSERT INTO request_po (item_name, item_code, item_description, item_price) VALUES (
'".$item_name[$j]."',
'".$item_code[$j]."',
'".$item_description[$j]."',
'".$item_price[$j]."');
if($result){
$j=0;
$count=sizeof($\u POST['po\u qty']);//我使用sizeof()获取行数
//使用insert\u id属性
$po_trans_id=$link->insert_id;
$user=$\会话[“用户名”];
对于($j=0;$j<$count;$j++){
$query=“插入请求采购订单(项目名称、项目代码、项目说明、项目价格)值(
“$item_name[$j]”,
“$item_代码[$j]”,
“$item_description[$j]”,
“$item_价格[$j]”);
而不是if(isset($\u POST['item\u name']))
我尝试了不同的方法,比如:
if ($result) {
$j = 0;
$count = sizeof($_POST['po_qty']); // ive use the sizeof() to get the count of the rows
// Use insert_id property
$po_trans_id = $link->insert_id;
$user = $_SESSION["username"];
for ($j = 0; $j < $count; $j++) {
$query = "INSERT INTO request_po (item_name, item_code, item_description, item_price) VALUES (
'".$item_name[$j]."',
'".$item_code[$j]."',
'".$item_description[$j]."',
'".$item_price[$j]."');
if($result){
$j=0;
$count=sizeof($\u POST['po\u qty']);//我使用sizeof()获取行数
//使用insert\u id属性
$po_trans_id=$link->insert_id;
$user=$\会话[“用户名”];
对于($j=0;$j<$count;$j++){
$query=“插入请求采购订单(项目名称、项目代码、项目说明、项目价格)值(
“$item_name[$j]”,
“$item_代码[$j]”,
“$item_description[$j]”,
“$item_价格[$j]”);
您是否收到任何错误。您在警报(数据);
中收到的输出是什么?@danish-khan-I,我收到的唯一错误是警报“本地主机说”,但没有任何正文打开chrome调试工具
转到网络
并点击按钮。单击URL并告诉您看到的内容。打印($\u POST)
在插入页面中。数组([item\u name]=>Array([0]=>)[item\u code]=>Array([0]=>)[item\u desc]=>Array([0]=>)[item\u price]=>数组([0]=>)其中是项目代码、项目名称等的输入字段。您应该使用输入值来输入是否有错误。您在警报(数据);
?@danish-khan-I中得到的输出是什么?本地主机说,我得到的唯一错误是警报但是空的body打开chrome调试工具
进入network
并点击按钮。点击URL并告诉你看到了什么。还有print\r($\u POST)
在你的插入页面中。数组([item\u name]=>Array([0]=>)[item\u code]=>Array([0]=>)[item_desc]=>数组([0]=>)[item_price]=>数组([0]=>)项目代码、项目名称等的输入字段在哪里?您应该使用“欢迎使用SO”输入您的值!请编辑一下您的答案,并解释一下