【发布时间】:2018-06-25 13:31:32
【问题描述】:
我正在使用此命令向表中添加值。 此代码有助于向表中添加多行,我们也可以通过选择不需要的行来删除一行。
但现在我必须在发布后将这些添加的行从 html 表插入到 mysql php 表中。
如何将添加的值从表中插入到 mysql 表中。
<script type="text/javascript" src="main.js" charset="UTF-8"></script><link rel="stylesheet" crossorigin="anonymous" href="https:///abn/main.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".add-row").click(function(){
var name = $("#name").val();
var email = $("#email").val();
var price = $("#price").val();
var markup = "<tr><td><input type='checkbox' name='record'></td><td>" + name + "</td><td>" + email + "</td><td>" + price + "</td></tr>";
$("table tbody").append(markup);
});
// Find and remove selected table rows
$(".delete-row").click(function(){
$("table tbody").find('input[name="record"]').each(function(){
if($(this).is(":checked")){
$(this).parents("tr").remove();
}
});
});
});
</script>
<table>
<thead>
<tr>
<th>Select</th>
<th>Product Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Total Price</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
<button type="button" class="delete-row">Delete Row</button>
<input type="button" class="add-row btn btn-success" value="Add Row">
【问题讨论】:
-
你需要
POST或GET你的数据从你的javascript到PHP,然后从PHP更新你的数据库。 -
使用 Ajax : api.jquery.com/jquery.ajax ?想法:您将数据从前端发送到 php 文件,然后发回响应。所以当你添加一行时,使用ajax将数据发送到一个php文件中,在php文件中插入新数据,这样你就可以插入/删除数据而无需重新加载页面
标签: javascript php mysql