Relay price to checkout page


Hello. I am working on a home-grown ecommerce solution and could use some help.

For now, my site offers subscriptions to users for access to premium content (e.g. news, articles, podccasts).

I have a “Subscribe” button in the top menu, and when someone clicks on that, I display a “membership-plans.php” page which shows a table of available member plans. Users can click on a “Select” (form) button for the option they want, and then are transferred to “checkout.php” where they will create an account and checkout all in one step.

As part of this, I need to come up with better solution than what I have now for determining the “Item Total” which is the cost of the subscription they chose.

Currently I am doing this…

In “membership-plans.php”, I have my 3 “Select” buttons, and when the form is submitted, I look at the $_POST array and stick whichever options was chosen into the $_SESSION variable.

For example, that might be…

$_SESSION['chosenPlan'] = $_POST['memberPlan-01'];

Then after I redirect them to the “checkout.php” page, that script can determine which option was chosen by looking at the $_SESSION variable, and then calculate the Order Total by maybe using a lookup like this…

IF ($_SESSION['chosenPlan'] = "memberPlan-01"){
  $orderTotal = $20

ELSEIF ($_SESSION['chosenPlan'] = "memberPlan-02"){
  $orderTotal = $30



The problem is that I have to hard-code lookup logic mapping the chosen Member Plan to a price, so if next week I introduce Member Plan 999 then I would have to update the above code.

I think I need a fresh set of eyes to look at what I am doing and offer a more streamlined (and scalable) solution!! :blush:


Combine a Table + Form

Your product information should be stored in a database table. This will define a product_id (auto-increment column), store a product category_id (defined in a separate table), a product name/title, and a product description. You would have a separate related table to hold product pricing with the product_id, price, and a start and end date (prices can vary over time - sales, price increases, coupons, renewal vs new subscription…)

To display product choices, you would query for the appropriate product information and dynamically display it. Any product selection would use the product_id. To get the price for any point in time you would query against the product_pricing table.


But that wasn’t my question…


It’s an answer on how to accomplish a streamlined and scalable solution.


But you’re telling me things I already know.

How about helping me figure out a streamlined solution to the problem I posed?

Or was my question not clear?


Maybe it would help if you explained why moving this to a db would not solve your problem


Okay, I’m clearly not making sense, so let’s start over!!

I am trying to build my first ecommerce site where I am selling subscritions/membership-plans to access premium content (e.g. articles, podcasts, etc.).

The flow goes like this…

  • User clicks on "Subscribe button in top menu

  • System displays a product-comparison grid like this sample

  • User clicks on the “Buy Now” button for the plan they want to buy.

  • User is taken to checkout page, where what they just selected is dislayed, plus all of the necessary fields to create an account and checkout all in one place.

Let’s say there are three offerings: Plan-A, Plan-B, Plan-C and the user chooses “Plan-B”.

Based solely off of the user clicking on the “Buy Now” button under Plan-B, I need to capture that choice and send it back to my php script.

Forget about databases and all of that, because I am NOT asking for help with that at this point.

I am trying to figure out HTML forms…

Hint: I want every button to say the same thing, e.g. “Select” or “Buy Now” or “Choose Me”, so I need a way to tell my php script WHICH OPTION was chosen!!

Right now I am leaning towards having there be a form for each product choice, and using a hidden form value to send the productID to my script, like this…

<td id=choice01">
<form id=choice-01 action="" method="post">
  <input name=planID" type="hidden" value="xy8011" />
  <input name="planChosen" tye="submit" value="Buy me" />
<td id=choice02">
<form id=choice-02 action="" method="post">
  <input name=planID" type="hidden" value="xy8012" />
  <input name="planChosen" tye="submit" value="Buy me" />
<td id=choice03">
<form id=choice-01 action="" method="post">
  <input name=planID" type="hidden" value="xy8013" />
  <input name="planChosen" tye="submit" value="Buy me" />

Once I get the html form figured out, then I can decide if I want to use a database or not.

Make sense now?


Can you use javascript?


I don’t know JavaScript, and want to get v1.0 done using what I do know which is HTML/CSS/PHP.

I plan on learning JavaScript soon, but one thing at a time.

Is there anything wrong with the code I posted above?



Can you please comment on the code I posted above?

It seems to work okay, although maybe there are better solutions.

And fwiw, I can use my code with a database solution, but that is for later on. Now I just need to get it working with certain values.