Forum Moderators: coopster
<?php
print "<html>
<head><title>Database Web Application</title></head>
<body bgcolor='white'>
<center><h1>Shop at DVD R US Now</h1></center>
<hr>";
//Establish Connection with MySQL Database
$username="XX";
$password="XX";
$database="products";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("unable to select database");
$query="SELECT * FROM inventory";
$result=mysql_query($query);
$num=mysql_numrows($result);
//Display database records in HTML table
print "<table border='0' width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td>
<table width='400' border='1'>";
$i=0;
while ($i < $num) {
$item_name=mysql_result($result, $i, "item_name");
$price=mysql_result($result, $i, "price");
$image_fn=mysql_result($result, $i, "image_file");
print "<tr>";
print "<td><img src='images/$image_fn'></td>";
print "<td><b><font face='arial'>DVD: $item_name</b>
<br>Cost:$ $price</font>";
print "<td><a href='addcart.php'>Add to Cart</a></td></tr>";
$i++;
}
print "</table>
</td>
</tr>
<br>
<p align='center'><font size='2'>
<a href='#'>Home</a> ¦ <a href='#'>Order Form</a> ¦ <a href='#'>Contact Us</a>
</font></p>
<hr>
</body></html>";
mysql_close();
?>
You can create a separate .php page for the content after then select the link for the product they want to buy. Then, for each of the links for the product, put the product name at the end like this...
print "<a href='addcart.php?$prod=item_name'>Add to Cart</a>";
...then on the other page do something like this...
$selected = $_GET['prod'];
if($selected == "DVD") {
print "You selected DVD!"; }
else if($selected == "Toy") {
print "You still play with toys?"; }
You can do something like this or choose one of the other ways that this can be done using forms and such...hope this kindof helps