Article 5JDBV Questions Re: multiple INSERT statements to server PHP

Questions Re: multiple INSERT statements to server PHP

by
pizzipie
from LinuxQuestions.org on (#5JDBV)
I have some questions regarding coding of multiple INSERT statements going to my server.

My code is based on an example I found in fiddle. Here is the code and my questions

Code below will run.

PHP Code:

Code:<?php
// Fri May 28, 2021 14:30
// multiAdd.php
// to serve multiInsert.html

set_include_path( '../include' );
error_reporting (E_ALL ^ E_NOTICE);

include('myPhpFunctions.inc');

//myprint($_POST); //bye("multiAdd.php Line 12"); Shows $_POST array - OK

print_r($_POST);

echo json_encode($_POST); // Returns Json data - OK

?>HTML Code:

Code:<!DOCTYPE html>

<!-- multiInsert.html -->
<!-- Adapted from http://jsfiddle.net/sperske/8e5ae/10/ -->

<html>
<head><title>testing multi insert function multiInsert.html 28May2021</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="../jquery/jquery-2.1.4.js"></script>

<style>

tbody#template {
display: none;
}

body {
font-family: roman, 'times new roman', times, serif;
font-size: 14pt;
margin: auto;
text-align: center;
background-color: #6795c8;
}

input {
font-size: 12pt;
color: blue;
}

</style>

</head> <!--=================== End <head> ===================== -->

<body>

<table id="tabledata">
<thead>
<th>Id</th>
<th>Vendor</th>
<th>OrderNo</th>
<th>DrugNo</th>
<th>Description</th>
<th>Cost</th>
<th>Refills</th>
</thead>
<tbody id="input"></tbody>
<tbody id="template">
<tr>
<td>
<input name="Id" type="text" />
</td>
<td>
<input name="Vendor" type="text" />
</td>
<td>
<input name="OrderNo" type="text" />
</td>
<td>
<input name="DrugNo" type="text" />
</td>
<td>
<input name="Description" type="text" />
</td>
<td>
<input name="Cost" type="text" />
</td>
<td>
<input name="Refills" type="text" />
</td>

</tr>
</tbody>
</table>
<button id="ActionAddRow">Add Row</button>
<button id="ActionSubmit">Submit</button>

<script type="text/javascript">

$(function () {
var addInputRow = function () {
$('#input').append($('#template').html());
};

addInputRow();
$('#ActionAddRow').on('click', addInputRow);
$('#ActionSubmit').on('click', function () {
var mydata = $('#input tr').map(function () {
var values = {};
$('input', $(this)).each(function () {
if (this.type === 'checkbox') { // org fiddle code
values[this.name] = this.checked; // ditto
} else {
values[this.name] = this.value;
}
});
return values; // to what ? - is this for ".get() ?"
})
.get(); //What does this do - does not work without this
$.post('multiAdd.php', {
mydata,
//json: JSON.stringify(data), Original fiddle code
//delay: 1 ditto
})

/* $.ajax({
type: "POST",
url: "multiAdd.php", This does not work - how to fix ??
data: mdata,
dataType: "json",
}) // ajax
*/
.done(function (response) {
alert("POST success");
console.log(response);
});
});
});

</script>

</body>
</html>latest?d=yIl2AUoC8zA latest?i=vJz3ScLKoA0:zIqFheQrBx0:F7zBnMy latest?i=vJz3ScLKoA0:zIqFheQrBx0:V_sGLiP latest?d=qj6IDK7rITs latest?i=vJz3ScLKoA0:zIqFheQrBx0:gIN9vFwvJz3ScLKoA0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments