Jump to content

[SOLVED] function not completing


samoht

Recommended Posts

<?php
function saveOrder($CPC)
{
    $orderId       = 0;
    $shippingCost  = 5;
    $requiredField = array('hidShippingFirstName', 'hidShippingLastName', 'hidShippingAddress1', 'hidShippingCity', 'hidShippingPostalCode',
                           'hidPaymentFirstName', 'hidPaymentLastName', 'hidPaymentAddress1', 'hidPaymentCity', 'hidPaymentPostalCode');
           
    if (checkRequiredPost($requiredField)) {
        extract($_POST);

        // make sure the first character in the
        // customer and city name are properly upper cased
        $hidShippingFirstName = ucwords($hidShippingFirstName);
        $hidShippingLastName  = ucwords($hidShippingLastName);
        $hidPaymentFirstName  = ucwords($hidPaymentFirstName);
        $hidPaymentLastName   = ucwords($hidPaymentLastName);
        $hidShippingCity      = ucwords($hidShippingCity);
        $hidPaymentCity       = ucwords($hidPaymentCity);
        //for clients with accounts.
        $ClientId                    =(int)($hidClientId);
        $ShipAddressId                =(int)($hidShipAddressId);
        $BillAddressId                =(int)($hidBillAddressId);
        $Email                         =($hidEmail);
                
        $cartContent = getCartContent($CPC);
        $numItem     = count($cartContent);
        
        // save order & get order id
        $sql = "INSERT INTO `orders` (
        `ClientId`, `ShipAddressId`, `BillAddressId`, `Email`, `OrderDate`,
        `OrderStatus`, `AssignedTo`, `DateAssigned`, `Location`, `FlagStatus`, `FlagStatus2`, `DateStatus`)
        VALUES (
        '$ClientId', '$ShipAddressId', '$BillAddressId', '$Email', NOW(),
        'New', NULL, NOW(), 'WS', 'N', NULL, NOW())";

        $result = dbQuery($sql) or die('no good order info');
        
        // get the order id
        $orderId = dbInsertId();
        
        if ($orderId) {
            // save order items
            for ($i = 0; $i < $numItem; $i++) {
                $sql = "INSERT INTO orderitems(OrderId, ProductId, OrderQty)
                        VALUES ($orderId, {$cartContent[$i]['ProductId']}, {$cartContent[$i]['qty']})";
                $result = dbQuery($sql);                    
            }
        
            
            // update product stock
            for ($i = 0; $i < $numItem; $i++) {
                $sql = "UPDATE product
                        SET QtyInStock = QtyInStock - {$cartContent[$i]['qty']}
                        WHERE ProductId = {$cartContent[$i]['ProductId']}";
                $result = dbQuery($sql);                    
            }
            
            
            // then remove the ordered items from cart
            for ($i = 0; $i < $numItem; $i++) {
                $sql = "DELETE FROM cart
                        WHERE CartId = {$cartContent[$i]['CartId']}";
                $result = dbQuery($sql);                    
            }                            
        }                    
    }
    
    return $orderId;
}

 

This function used to be working fine  - but now I keep getting a $orderId of 0???

 

but when I insert the sql directly into phpMyAdmin - it updates the table just fine?  - I have also tested each of my variables and they work fine. Any idea where I could be missing something?

 

let me know if you need more code.

 

Link to comment
https://forums.phpfreaks.com/topic/71411-solved-function-not-completing/
Share on other sites

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.