This question already has an answer here:
I am listing product list from products table which i select product_group on previous page. In this list, i show product names and empty input in every row of table. Into the empty inputs, manually i write number of products which i count in my shop. After filling all the products numbers (rows in this html table) i want to insert them into another mysql table row by row for each product.
Here is my html table codes:
<table class="table table-responsive" width="100%" border="1">
<tbody>
<tr style="background-color:#C2E17C">
<td align="center" width="80%"> Stok İsmi</td>
<td align="center" width="20%"> Sayım Miktarı</td>
</tr>
<?php
$personelcek = mysql_query("SELECT * FROM stoklar WHERE sto_durum='acik' AND sto_altgrup_kod = '".$_REQUEST['sta_RECno']."' ORDER BY sto_isim ASC");
while ($a= mysql_fetch_array($personelcek)){
$sto_RECno = $a['sto_RECno'];
$sto_isim = $a['sto_isim'];
echo'
<tr>
<td align="left" width="80%"><input class="input1" type="hidden" name="stok_kodu[]" value="'.$sto_RECno.'" readonly>'.$sto_isim.'</td>
<td width="20%"><input style="text-align:right" class="input1" type="text" name="sayim_miktari[]" value=""></td>
</tr>';}?>
</table>
And also there is one more input outside of the table which i retrieve the product_group_id as this:
<input type="hidden" name="alt_grup_kod[]" value="<?php echo $_REQUEST['sta_RECno']; ?>">
And the last thing, i want to retrieve existing count numbers from mysql products table for each product.
As a summary, i want to insert every product one by one into another mysql table including product_group_id, product_id, existing_count_numbers and manually written numbers.
I tried like this but everytime i get errors:
$stok_kodu = $_POST['stok_kodu'];
$stoklar = array($stok_kodu);
$sayim_miktari = $_POST['sayim_miktari'];
$sayim_miktarlari = array($sayim_miktari);
$alt_grup_kod = $_POST['alt_grup_kod'];
$alt_gruplar = array($alt_grup_kod);
$stok_miktarlari = array();
$miktar_cek = mysql_query("SELECT * FROM stoklar WHERE sto_RECno = '".$stok_kodu."' ORDER BY sto_RECno");
while ($miktar_al = mysql_fetch_assoc($miktar_cek)){
$stok_miktari[] = $miktar_al['sto_miktar'];
foreach ($stok_kodu as $stoklar){
foreach ($sayim_miktari as $sayim_miktarlari){
foreach ($alt_grup_kod as $alt_gruplar){
foreach ($stok_miktari as $stok_miktarlari){
$sayim_kaydet = mysql_query("INSERT INTO sayim_sonucu (alt_grup_kod, stok_kodu, sayim_miktari, stok_miktari) VALUES ('$alt_gruplar', '$stoklar', '$sayim_miktarlari', '$stok_miktarlari')");
}}}}}
Any idea how i can tidy all these codes and insert every product into another table of mysql database?
</div>