So I have a JS script that adds a and it’s relevant which also adds name depending on how many table data there are.
var newRowHtml = '<tr>' +
'<td><input type="text" name="pds_4_input_'+count[0]+'" class="underline_input"></td>' +
'<td><input type="text" name="pds_4_input_'+count[1]+'" class="underline_input"></td>' +
'<td><input type="date" name="pds_4_input_'+count[2]+'" class="underline_input"></td>' +
'</tr>';
table.append(newRowHtml);
Resulting in something like this (these ones however are default, so adding one would result in pds_4_input_4 and so on…):
<tr>
<td><input type="text" name="pds_4_input_1" placeholder="Apple"></td>
<td><input type="text" name="pds_4_input_2" placeholder="Banana"></td>
<td><input type="text" name="pds_4_input_3" placeholder="Cranberry"></td>
</tr>
And I have already built the simple php code to bind those input values into my db and it works.
<?php
session_start();
require 'connection.php';
function dataToPDS4($mysqli) {
$input0 = $_SESSION['pds_id'];
$input1 = $_POST['pds_4_input_1'];
$input2 = $_POST['pds_4_input_2'];
$input3 = $_POST['pds_4_input_3'];
$sql = "INSERT INTO pds_4 (accID, Apple, Banana, Cranberry)
VALUES (?, ?, ?, ?)";
$stmt= $mysqli->prepare($sql);
$stmt->bind_param("isss", $input0, $input1, $input2, $input3);
$stmt->execute();
$stmt->close();
}
?>
Now, I have to figure out a way to bind the new parameters after pds_4_input_3 brought unto by JS script.
I tried using arrays to bind them in PHP however it seems it doesn’t quite work (?) and stupid little me didn’t save the code so I can’t post it here so; sorry about that.
I’m expecting to just get a link to a video/tutorial or thread that would allow me to save the added table rows and table data. If someone is willing to share part of a code for me to solve as well that’d be swell as well.
That said, thank you in advance and have a good day!
Edit: Forgot to edit bind_param types.
Edit 2: Edited the values placeholders in $sql.