You can insert many values into SQL with a single command (though not recommend, use PDO), such as
INSERT INTO MyTable ( Column1, Column2 ) VALUES
( Value1, Value2 ), ( Value1, Value2 )
If using jQuery, you can use $.post()
to send data to your web server (PHP). Here’s an example:
var items = []
$('li .item').each(function(index, item) {
items.push({
name: item.child('.name').text(),
cost: parseFloat(item.child('.cost').text()),
})
});
$.post("post.php", {
data : JSON.stringify(items),
contentType : 'application/json',
});
And in your post.php
:
$items = json_decode($_POST['data']);
// Insert into DB
You should be using Prepared Statements (PDO) to insert safely in your database.
1
solved How can I insert multiple li items each in a different row in mysql with a single click (jQuery, PHP, SQL) [closed]