0
good morning. I’m trying to make a shopping ordering system. I would like to know how to receive $_POST values and send them to a bank. The problem is that this $_POST information is dynamic. I would like to create a special array and insert this information into a mysql table.
Add the include items button:
$('#addmore').click(function(){
// Get last id
var lastname_id = $('.tr_input input[type=text]:nth-child(1)').last().attr('id');
var split_id = lastname_id.split('_');
// New index
var index = Number(split_id[1]) + 1;
// Create row with input elements
var html = "<tr class='tr_input'>\n\
<td><center><input type='text' class='username' id='username_"+index+"' name='username_"+index+"' placeholder='Informe o produto'></center></td>\n\
<td><center><input type='text' class='id_' id='id_"+index+"' name='id_"+index+"' readonly></center></td>\n\
<td><center><input type='text' class='name' id='name_"+index+"' name='name_"+index+"' ></center></td>\n\
<td><center><input type='text' class='salary' id='salary_"+index+"' name='salary_"+index+"' onKeyUp='moeda(this);' ></center></td>\n\
<td><center><button type='button' class='btn btn-warning' onclick='remove(this)'>Excluir</button></td></center></tr>";
// Append data
$('tbody').append(html);
});
TR for data entry:
<tr class='tr_input'>
<td><center><input type='text' class='username' id='username_1' name="username_1" placeholder='Informe o produto'></center></td>
<td><center><input type='text' class='id' id='id_1' name="id_1" readonly></center></td>
<td><center><input type='text' class='name' id='name_1' name="name_1" required></center></td>
<td><center><input type='text' class='salary' id='salary_1' name="salary_1" onKeyUp="moeda(this);" required></center></td>
<td><center><button type="button" class="btn btn-warning" onclick="remove(this)">Excluir</button></center></td>
</tr>
form to send via post:
<form method="post" action="cad-novo-pdc.php">
thanks friend, but it did not work, he is only taking the first item I include, the others do not print on screen.
– Ronierick Holanda
The names of the inputs that you showed the print, are the same of the HTML code ?
– Leo
Buddy, I figured out why he’s only getting the first line. In your JS, you’re doing the adding of the products the wrong way. You are also changing the ID value of the items. You should make this addition using as parameter the
name
Array-like as I mentioned to you. Since you’re changing the element ID, it’s only picking up the first line anyway. Take the part of changing the Ids that you’ll see will work.– Leo
I forgot to say that applies also to the
name
, in the same you do not need to put a different index in JS. It would be better if you do aclone()
from your table and then give aapend()
than to do in the present way. Leave the name as Array instead of adding index’s to it, because it is through the name that the data is sent to the Database. So if you clone(), it works much better, as it will already be cloned as Array.– Leo