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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.