Re: Check out system for Shopping Cart

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Vernon,

CC messages to php-general to keep responses on-list. See my comments
inline.

On Thu, May 21, 2009 at 12:06 PM, Vernon St.Croix <vstcroix@xxxxxxxxxxx>wrote:

>
> I have amended as you advised and the mysqli errors are now gone. Thanks
> for that.
>
> I however have another one I can't get rid of:
>
>
> *Warning*: Invalid argument supplied for foreach() in *
> C:\wamp\www\draft\checkout.php* on line *53*
> Your order could not be processed.
>
>
> *checkout.php*
>
> <?php
>

<code snipped>

>
>
>     include ("mysql_connect.php");
>
>     //Turn off autocommit
>
>
>     $con = mysqli_connect ("localhost", "root", "", "rum");
>

>     mysqli_autocommit($con, FALSE);
>
>     //Add orders to the order table
>
>     $sql = "INSERT INTO orders (user_id, total) VALUES ($user, $total)";
>
>     $r = mysqli_query($con, $sql);
>

<code snipped>

>
>      *   foreach ($_SESSION['cart'] as $id => $item){*
>
>         $qty = $item['quantity'];
>         $price = $item['price'];
>
>         mysqli_stmt_execute($stmt);
>
>         $affected += mysqli_stmt_affected_rows($stmt);
>
>         }
>

The reason you're getting this warning is that foreach is expecting
$_SESSION['cart'] to be an array.  Do a print_r() or var_dump() of
$_SESSION['cart'] to see what is actually being passed to the function.

        mysqli_stmt_close($stmt);
>
>         if ($affected ==count($_SESSION['cart'])) {
>
>         mysqli_commit($con);
>
>         echo'Thank you for your order';
>
>         }else{
>
>         mysqli_rollback($con);
>
>         echo'Your order could not be processed';
>
>         }
>
>         }else{
>
>         mysqli_rollback($con);
>
>         echo'System error';
>
>         }
>
>         mysqli_close($con);
>
>
>
>
>         include ("footer.html");
>
>
>         ?>
>
>
> VEE
>

-- Lex

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux