troubleshooting Question

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

Avatar of James Allan
James Allan asked on
PHPjQueryAJAX
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.
full-ui.png
this is where i get all the values to post in DB.
include_once '../incluedes/conn_cms.php';//session started here 
		
 if(isset($_GET['submit_post'])){

			$date = date('Y-m-d');
		 	$fabric=$_GET['fabric'];
		 	$size=$_GET['size'];
		 	
		 	$desenho=$_GET['desenho'];
		 	$numero=$_GET['numero'];
		 	$vari=$_GET['vari'];

		 	$qnty=$_GET['qnty'];
		 	$cost=$_GET['cost'];
		 	$subT=$_GET['subtotal'];


		 	$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)){
		    	$tecido=$rows['tecido'];
		   	}

		 	$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: " ;
				}
			$conn->close();
			 }

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">
            <thead>
            <h4></h4>
              <tr>
              <th>Image</th>
              <th>Produto</th>
              <th>Fabric</th>
              <th>Size</th>
              <th>Qntd</th>
              <th>Cost</th>
              <th>sub.total</th>
              </tr>
            </thead>
            <tbody >
             
              
          <?php cart(); ?>
            
          
            </tbody>
          </table>
          <div class="form-group">
                <input name="submit_post" class="first" type="submit" >
             </div>
          </form>

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.

jQuery("input.second").click(function(){
   jQuery("input.first").trigger('click');
   return false;
});
ASKER CERTIFIED SOLUTION
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