Site icon WDB24

PHP Shopping Cart – Create Single Product Page

PHP

This is fourth tutorial in PHP Shopping cart series and today I will create single product page. I will display single product data with one image.

First I will create a single-product.php page in folder root.

Single Product Page:

Now open single-product.php file and paste below code

In the above code first of all I have added session_start() function which will use in add to cart functionality. After that I included 2 php files and then I check the condition of getting product id or not. Next I wrote sql query to get product with image. If I get the product I store that product array in $getProductData or otherwise I will create a $error variable to print ‘404 not found error’.

Now lets move to HTML part of the single product page.

As you can see in above code that at start I just add condition of isset and is_array just to avoid notice and warning. And then I put image on left. Heading, short description and price on right side and long description in the end. I also created a form for add to cart functionality which I will discuss in my next tutorial.

Also read:

Exit mobile version