i am building a simple online portal and i have done all the login ,registration pages and all the fields successfully get uploaded in the database but now

all i got is a product display page and an shopping cart

1. i want help is how do i pass the information from the product page to cart page
2.concurrently update in the database i.e. mysql
3.if customer wants he can remove a product from the cart.

can u help me with all..am wondering since 10 days now hope you guys help me out.thank you.

Dani AI

Generated

Follow-up for — since 's session tip got the cart working and pointed to POST/AJAX, here is a practical, durable checkout workflow and database pattern to move the session cart into MySQL, validate it, and handle removals safely.

Decide when to persist: recommended practice is to write a real order to the DB only when checkout is confirmed (shipping + payment). Alternatively keep a draft cart table for logged-in users. Typical schema: orders (id, user_id, total, status, created_at, shipping fields), order_items (id, order_id, product_id, sku, name_snapshot, qty, unit_price, line_total). Always snapshot name/price in order_items so future product changes don’t corrupt past orders. Use InnoDB and server-side prepared statements (PDO or MySQLi). Recalculate totals on the server — never trust client-sent totals.

Example checkout transaction (PDO-style pseudocode):

$db->beginTransaction();

$sth = $db->prepare("INSERT INTO orders (user_id,total,status,created_at) VALUES (?,?,?,NOW())");
$sth->execute([$user_id, $total, 'pending']);
$order_id = $db->lastInsertId();

foreach ($cart as $item) {
  $db->prepare("INSERT INTO order_items (order_id,product_id,qty,unit_price,name) VALUES (?,?,?,?,?)")
     ->execute([$order_id,$item['id'],$item['qty'],$item['price'],$item['name']]);

  $upd = $db->prepare("UPDATE products SET stock = stock - ? WHERE id = ? AND stock >= ?");
  $upd->execute([$item['qty'],$item['id'],$item['qty']]);
  if ($upd->rowCount() == 0) { $db->rollBack(); /* handle out-of-stock */ exit; }
}

$db->commit();

Practical tips: keep the session cart as the editable source until final submit; if saving drafts, mark them with status='draft'. For stock safety use atomic UPDATE (shown) or SELECT ... FOR UPDATE inside the same transaction to avoid oversells. Use CSRF tokens, server-side validation, and sanitize inputs. For payment flows, mark payment_status after gateway callback and only finalize shipments thereafter. These steps cover passing the session cart into MySQL, concurrent-safe stock updates, and clean removal handling.

Recommended Answers

All 3 Replies

Thanx the session thing just helped me out..i was able to make the cart too and update it but now the problem i face is


the checkout and ordering thing ... i want to pass the session variables of my cart to
the database and then let the user fill the shipping info and process the order if i get any sort of help on this will be thankful..

i am building a simple online portal and i have done all the login ,registration pages and all the fields successfully get uploaded in the database but now

all i got is a product display page and an shopping cart

1. i want help is how do i pass the information from the product page to cart page
2.concurrently update in the database i.e. mysql
3.if customer wants he can remove a product from the cart.

can u help me with all..am wondering since 10 days now hope you guys help me out.thank you.

Several answers could come handy for your request, I will try to mention few:

  1. Passing information to other pages could be done by either POST or GET requests in e.g. sending product id's and handling them with the $_POST, $_GET or $_REQUEST superglobals . Or you may store the chosen products in a temporary cookie/session and catch them at the cart page with $_COOKIE or $_SESSION
  2. You may update the database entries at the cart page when the request is received and validated. Or if you are heading to dynamic content and interval-based updates, you may need to use AJAX requests and jQuery is what I suggest using for that
  3. This depends on the method you used to update.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.