Jump to content

Issue with inserting array into Database


vmicchia

Recommended Posts

hey there I have an issue when I am inserting an array into the database. When I run the insert statements the records get inserted but it is sometimes one less record than is in the table and sometimes even less. for example if I have 5 records it only inserts the first 4. This is confusing because when I echo out the statement in the loop it shows all 4 insert statements. my loop for inserting looks like this:

 

if(isset($_SESSION['cushArray'])){
    
    foreach($_SESSION['cushArray'] as $key => $value){
        $getCushSKU = "SELECT SKU FROM Cushion WHERE Name = '".$value['Cushion']."'";
        //echo $getCushSKU;
        $resultGetCushSKU = mysql_query($getCushSKU);
        $getResultGetCushSKU = mysql_fetch_assoc($resultGetCushSKU);
        //echo $getResultGetCushSKU['SKU'];
        $getFabricSKU = "SELECT SKU FROM Fabric WHERE Name = '".$value['Fabric']."'";
        
        $resultGetFabricSKU = mysql_query($getFabricSKU);
        $getResultGetFabricSKU = mysql_fetch_assoc($resultGetFabricSKU);
        
        if($_SESSION['cushArray'][$i]["ContWeltFabric"] != "N/A"){
            $getWeltFabricSKU = "SELECT SKU FROM Fabric WHERE Name = '".$value['ContWeltFabric']."'";
            $resultGetWeltFabricSKU = mysql_query($getWeltFabricSKU);
            $getResultGetWeltFabricSKU = mysql_fetch_assoc($resultGetWeltFabricSKU);
        }else{
            $getResultGetWeltFabricSKU = "N/A";
        }
        
        $sqlCush = "INSERT INTO OrdersCushion(OrderID, ProductSKU, FabricSKU, WeltFabricSKU, Quantity, ButtonColor, ZipperColor, Fill) VALUES('".$getOrderIDNum['OrderID']."', '".$getResultGetCushSKU['SKU']."', '".$getResultGetFabricSKU['SKU']."', '".$getResultGetWeltFabricSKU['SKU']."', '".$value['Quantity']."', '".$value['Button']."', '".$value['Zipper']."', '".$value['Fill']."') ";
        
        //echo $sqlCush;
        
        $resultCush = mysql_query($sqlCush);
    }
    
}

 

any help is much appreciated

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.