troubleshooting Question

How can i post a php foreach loop in my database.

Avatar of James Allan
James Allan asked on
13 Comments2 Solutions582 ViewsLast Modified:
This is my cart function.
As you can see my function creates a foreach loop for my products.
And i used a hidden inputs to hold values because td tags does not post anything.
this is where i get all the values to post in DB.
include_once '../incluedes/conn_cms.php';//session started here 

			$date = date('Y-m-d');


		 	$pedido=$date." ".$_SESSION['userName']."-".$_SESSION['userLName'];

			 $query = "SELECT * FROM almofadas WHERE id_price='$fabric'";
		   	 $result = mysqli_query($conn,$query);
		   	 while($rows = mysqli_fetch_assoc($result)){

		 	$ins_sql = "INSERT INTO orders (fabric,size,product_quantity,order_id,product_img,product_title,variante,product_cost,product_subtotal) 
                     VALUES ('$tecido', '$size' , '$qnty', '$pedido', '$desenho', '$numero', '$vari', '$cost', '$subT')";
		 	if ($conn->query($ins_sql) === TRUE) {
				echo "New record created successfully";
				} else {
				echo "Error: " ;

But the problem is when i post in my database it only gets the first product in my cart.
I need to post each products in my DB.
How i will do that?

This is my form ...

<form action="postOrder.php" method="GET" enctype="multipart/form-data" class="form-horizontal">

      <div class="container">
        <div class="row">
          <table class="table table-striped table-hover" id="myTable">
            <tbody >
          <?php cart(); ?>
          <div class="form-group">
                <input name="submit_post" class="first" type="submit" >

In my footer i have a button where it triggers a hidden submit button.
full ui
this is my script to trigger the hidden submit button.

   return false;
Join our community to see this answer!
Unlock 2 Answers and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros