I have asked around and tried a few things, I am pretty new to php and need help really badly. I need to pass some information to a table once a user presses a submit button from a shopping cart here is some of my code. I need to pass product name, price total, quantity. and cart total into a customers table with a auto increment id field. Underneath that is the code I was given is an example to help but I cant get it to pass anything to the table but 0.00 and the date. I know its a long first post but I really need help. <?php $priceTotal=""; $product_name=""; $price=""; $details=""; $cartOutput=""; $cartTotal=""; if(!isset($_SESSION["cart_array"])||count($_SESSION["cart_array"])<1){ $cartOutput="<h2 align='center'>your cart is empty</h2>"; }else{ //index starts at 0 $i=0; foreach($_SESSION["cart_array"]as $each_item){ $item_id=$each_item['item_id']; $sql=mysql_query("SELECT * FROM products WHERE id='$item_id'LIMIT 1"); while($row=mysql_fetch_array($sql)){ $product_name=$row["product_name"]; $price=$row["price"]; $details=$row["details"]; } $pricetotal=$price * $each_item['quantity']; $cartTotal=$pricetotal + $cartTotal; //formats currency setlocale(LC_MONETARY, "en_GB"); $pricetotal=money_format("%!10.2n",$pricetotal); //Dynamic tabel starts here $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '"></a><br/><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name . '" width="117" height="178" border="1" /></td>'; $cartOutput .= '<td>' . $details . '</td>'; $cartOutput .= '<td>£' . $price . ' </td>'; $cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>£' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '"type="submit" value="x"/><input name="item_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .='</tr>'; //items add by 1 $i++; } setlocale(LC_MONETARY, "en_GB"); $cartTotal=money_format("%!10.2n",$cartTotal); $cartTotal="<div align='right'>Cart Total:£" .$cartTotal. " </div>"; } ?> example code <?php session_start(); $_SESSION["valid_id"]; $_SESSION["cost"]; $_SESSION["products"]; $_SESSION["order"]; $items = explode(",",$_SESSION["order"]); include ("dbConfig.php"); include ("cart.php"); $sql="SELECT * FROM products"; $result=mysql_query($sql); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { for( $i = 0; $i < count($items); ++$i ) { if ($items[$i]==$row['product_id']) { $order = $order.$row['title'].","; } } } $sql='INSERT INTO orders VALUES ("",'.$_SESSION["valid_id"].',"'.$order.'",'.$_SESSION["cost"].')'; mysql_query($sql); $_SESSION["cost"]=0; $_SESSION["products"]=0; $_SESSION["order"]=""; header ('Location: index.php?order=true'); ?> PHP:
It is a very long post. Rather than spend all of my time dissecting each part, how about you let us know what specifically is wrong. By the way, welcome to Digital Point.
Thanks, the cart works fine my items are added and the total cart price shown, I then want the user to submit and the info added to a table as I said that's where I am stuck I was thinking something like adding the button in a form linked to a page running an insert query like. $product_name=$_POST["product_name"]; then a SQL insert statement adding the variables I want into a customer table just for reference but I dont know how or if this is correct. short version user presses submit button and info enters table.