In Chapter 4, we authored the panel to display the latest wines that have been added to the winestore. We noted that the panel used in the winestore has Add to Cart functionality, in which a user can click on a link, and a bottle or case of wine is added to her shopping cart. This functionality is implemented using an embedded URL that is dynamically created from data in the database. Example 5-7 displays the code used to add the "Add to Cart" link that's embedded in the panel. The code creates a URL with parameters that specify the quantity and the product to add to the shopping cart.
Example 5-7. The code used to add the "Add to Cart" link
echo "<tr align=\"right\"><td>" . "<a href=\"example.5-8.php?qty=1&wineId=" . $row["wine_id"] . "\">Add a bottle to the shopping cart</a>" . "</td></tr>";
The code fragment in Example 5-7 creates a link such as:
http://localhost/example.5-8.php?qty=1&wineId=801
The URL parameter wineId
is formed with the database wine_id
attribute value that is associated with the current wine being displayed in the panel. When the user clicks the link, example.5-8.php is requested and the parameters are supplied to the script. The user can type the URL directly her their web browser with the same effect, or you can author a <form>
for the same purpose. We discuss the script example.5-8.php in the next section.
|