Fixed Array Value is not inserting in MYSQL/PHP

Here below my code . its working fine, only $itemsize is not inserting any data in db. Others filed are okay. FYI $itemsize will repeatedly insert in many row following $friendarray as $s666s this data.

$friendslist = 
   "$s4s,$s6s,$s8s,$s10s,$s12s,$s14s,$sxss,$sss,$sms,$sls,$sxls,$sxxls";
        $friendarray = explode(",", $friendslist);
        $sizelists ="4,6,8,10,12,14,XS,S,M,L,XL,XXL";
        $size = explode(",",$sizelists);
        foreach ($size as $itemsize){
                                          echo "<li>$itemsize</li>";
                                           }

        for ($n = 0; $n < count($friendarray); $n++) {

        $friendidpush = "('".$style."','".$order."','".$color."','".$itemsize."','".$friendarray[$n]."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";
    }
        $query = "INSERT INTO freddyhipment (style, orderno, col, s4s, s6s, ctnqty, invoice, kcgmt, season, buyer, factory) VALUES ";
        $friendarray = explode(",", $friendslist);
        foreach ($friendarray as $s666s) {

            $query .= "('".$style."','".$order."','".$color."','".$itemsize."','".$s666s."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";

        }
        $query = substr($query, 0, -1); // remove trailing comma

$itemsize must be empty, because $size is not defined.

I got the solution as below…

$friendslist = "$s4s,$s6s,$s8s,$s10s,$s12s,$s14s,$sxss,$sss,$sms,$sls,$sxls,$sxxls";
$friendarray = explode(",", $friendslist);
$sizelists ="4,6,8,10,12,14,XS,S,M,L,XL,XXL";
$sizearray = explode(",",$sizelists);

$frienduserarray = array();
$sizeuserarray = array();

for ($n = 0; $n < count($friendarray) && $n < count($sizearray); $n++) {


$friendidpush = "('".$style."','".$order."','".$color."','".$sizearray[$n]."','".$friendarray[$n]."','".$ctnqty."','".$invoice."','".$kcgmt."','".$season."','".$buyer."','".$factory."'),";
//array_push($frienduserarray $sizeuserarray, $friendidpush);

}
$query = "INSERT INTO freddyshipment (style, orderno, col, sizes, qty, ctnqty, invoice, kcgmt, season, buyer, factory) VALUES ";
$friendarray = explode(",", $friendslist);
$sizearray = explode(",", $sizelists);
foreach ($friendarray as $index => $s666s) {
$s888s = $sizearray[$index]; 
$query .= "('".$style."','".$order."','".$color."','".$s888s."','".$s666s."','".$ctnqty."','".$invoice."','".$ kcgmt."','".$season."','".$buyer."','".$factory."'),"; 
}
$query = substr($query, 0, -1);

$x++;

if (mysqli_query($conn,$query)) {

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.