Urgent. how will i get the value of quantity here?




Is this for school?

Well, to read a value from a text input field, you use the $_POST() and assign it to a variable.
In a simple example like this: $quantity_input = filter_input(INPUT_POST, “quantity1”);
This is if the first one you circled is named quantity1. If you have four rows of data or a larger number,
you have to name the values different names. quantity1, quantity2, etc. Then process them as needed.
Once you get the inputted value, you multiply it by the price which as you show is different in each line.
So, you need to have the prices named price1, price2, price3, etc.

Now with that said, you do not have a button for submitting the form. So, maybe you are thinking of doing this using JQuery. In which case you still need to have multiple names for the prices and quantity fields.

Any way you decide to do it, you need to show us some code on what you have done so far so we can help you with a solution…


This is the code in cart.php

<?php $main_subtotal = 0; $main_shipping_charge = 0; // create a product_id_stack $product_id_stack = ""; foreach ($carts as $key => $cart) { $cart_id = $cart['id']; $cart_product_id = $cart['product_id']; // add product_id to the product_id_stack $product_id_stack .= $cart_product_id.","; $product = $db->Fetch("*","product","id='$cart_product_id'"); /*shipping charge formating*/ if ($product['shipping'] == 0) { $shipping_text = "FREE"; $shipping_price = 0; }else{ $shipping_text = "".$product['shipping']; $shipping_price = $product['shipping']; } $subtotal = $product['sp'] + $shipping_price; echo " {$product['name']} {$product['sp']}.00 php <input type='submit' name='submit' id='submit' {$subtotal}.00 php "; /*calculate all the shipping charge*/ $main_shipping_charge = $main_shipping_charge + $shipping_price; /*calculate all the sp*/ $main_subtotal = $main_subtotal + $product['sp']; } ?>

But I Remove the total

this is the code in the buy.php

		//decrypt the product id
		$product_id_stack_encrypted = escape($_POST['product_id_stack']);
		$product_id_stack = encryption("decrypt", $product_id_stack_encrypted);

		$user_id = $_SESSION['id'];
		$time = time();
		$insert = $db->Insert("buy","'','$user_id','$name','$email','$mobile','$city','$pincode','$address','$time','','Processing','1','$product_id_stack'");
		if ($insert) {
			/*get the last_inserted_id*/
			$buy_id = mysqli_insert_id($mysqli);
			/*inactive the row from cart table*/
			$update = $db->Query("UPDATE `cart` SET `active`='n',buy_id='$buy_id' WHERE `user_id`='$user_id'");
			if ($update) {
				$result['type'] = "success";
				$result['type'] = "error";
				$result['message'] = "Unable to update cart try again";

				/*delete buy record ifuser  system was not able to update the cart table*/
				$delete = $db->Delete("buy","id='$buy_id'");
			$result['type'] = "error";
			$result['message'] = "Opps! try again";

	echo json_encode($result);


Hard to follow your code from what you displayed to us.

It appears you save the “buy” info into your database. You UPDATE the table cart when it is inserted.
It would be there that you need to calculate the totals for each row before you update the cart.
Actually, it appears you would do that in your ->insert(“buy”) area. You must have a total in the buy table.
But, you are not adding the total in it from the code you posted.

Not sure if that is what you need…