0

When I press the "Buy Now" button, I would like it to copy over my product details (Name, Price & Image) and take me over to a checkout form; where I can 'purchase' the product.

Right now when I click the "Buy Now" button it will take me to an HTML page with a checkout form (without the product details).

    {

    $link = "checkout.html";
    $button = "button";        
    $style = "style=";
    print "<div class='product-card'<h4 style='padding:1em;'><b>" . $info['Name']."</h4></b><h4><b>Price: $". $info['Price']."</b></h4><img src=../images/".$info['ProductID'].".png ".$style."width:180px;height:120px;><br><br><a href=".$link."><button class=".$button.">Buy Now</button></a></div>";

    } 
}
Saveen
  • 4,120
  • 14
  • 38
  • 41

1 Answers1

0

Using PHP and $_GET variables will be the easiest way. Your link will look something like this: checkout.php?name=productName&price=1234&image=productImage

Then on the purchase page you can get those variables with:

$price = $_GET['price'];
etc...

However please be aware that this is not safe. Users could easily manipulate those variables by changing the URL.

Instead you should only place the productId in the URL like so: checkout.php?productId=1234

Then on the purchase page you can access the database for the product details like the name, image, price etc. using the productId from the URL with $_GET['productId'].

More information about using $_GET variables: GET URL parameter in PHP and from the PHP manual

Kelvin
  • 320
  • 4
  • 19
  • So I would change the link code to the one you made for me. But what actually would the code be for displaying the product, or displaying the product information in a form to checkout? – Ronald Adams May 24 '19 at 08:46
  • @RonaldAdams You could use the productId from the URL to make a Database call and retrieve the specific product information. Then you could do the same as you are doing now with `$info['Name']` for example to display the product details on the purchase page. – Kelvin May 24 '19 at 09:04