Skip to content
Advertisement

PHP total order

I have a site that displays items with radio buttons. I want to make the PHP code display the total for the user when they submit the code.

Below is the code I have so far along with the prices for each item that would be in the store.

JavaScript

The HTML code I’m working with is posted below that is for the webstore.

JavaScript

Advertisement

Answer

Simple: quantity * price.

JavaScript

PHP is loosely typed and will convert the form quantity strings to integers for you, and will also retain the floating point prices in the multiplication.

This uses the php7 null coalescing operator (??) to set the default quantity to 0 if any of the form elements are not submitted.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement