Example of the SQL/php code, the second query is applicable. I have created a user input that submits the id variables into a MySQL database. These user inputs are cloned multiple times within the form, thus resulting in multiple duplicate id's/names, however one column (lets call it column 1) is different for each clone.
Now, once the input has been added and the form is submitted it only appends the last form entry into the database table, which I expected.
Is there a way that all these copies can be added to the table, perhaps based on the variance of Column 1? I was thinking something like: for each Column 1 INSERT INTO database1 ...
EDIT
Some code:
HTML:
<style>
.hidden {
display: none;
}
</style>
<body>
<div id="samplesinfo" class="samplesinfo hidden">
<input type="text" id="column1" name="column1" value="1" readonly>
<input type="text" name="column2">
</div>
<button id="btn">Paste</button>
<div>
<h3>Paste Below</h3>
</div>
<form>
<div id="paste">
</div>
<button type="submit" name="submit">Submit</button>
</form>
jQuery:
$(document).ready(function() {
var sample = 1;
$("#btn").click(function() {
var element = $(".samplesinfo.hidden").clone(true);
element.removeClass("hidden").appendTo("#paste:last");
sample++;
$("#column1").val(sample)
});
});
and php:
if (isset($_POST['submit'])) {
$column1 = mysqli_real_escape_string($conn, $_POST['column1']);
$column2 = mysqli_real_escape_string($conn, $_POST['column2']);
$query = "INSERT INTO db1 ('column1', 'column2')
VALUES ('$column1', '$column2');";
mysqli_query($conn, $query);
header("Location: ../web_page/analysis_page.php?add_order=success");
}