Hi All,
I am trying to develop a shopping cart. This cart takes the values from the form and places them into a temp table created to hold the data serverside. The interesting thing is that the form is dynamic. Each product MAY have certain options that only appear when the page for that (well actually it is one page that is dynamically generated with PHP based on an index of products) item is clicked. The challenge is to create the cart table and the SQL statement to allow for the options, and of course not all options have to be choosen.
Here is the script for the table:
Create table $PHPSESSID (
item_sold_id int(10) NOT NULL auto_increment,
date_sold timestamp(14) NOT NULL,
prod_ID int(10) NOT NULL,
prod_name varchar(50), NOT NULL,
distrib_id int(10) default NULL,
quantity_purch tinyint(2) NOT NULL,
option_name varchar (30) NULL,
option_price float (10,2) NULL,
total_price float(10,2) NOT NULL,
PRIMARY KEY (item_sold_id),
UNIQUE KEY item_sold_id(item_sold_id),
KEY item_sold_id_2(item_sold_id)
);
Here is the code that creates the form with the data for the product:
$row = mysql_fetch_array($SQLResult);
$PNum = $row["prod_id"];
$Ptype = $row["prod_type"];
$PName = $row["prod_name"];
$PPrice = $row["prod_price"];
$PDescription = $row["prod_description"];
$PbigPic = $row["gulf_prod_pic"];
mysql_free_result($SQLResult);
?>
<table cols = 2 bgcolor = white border=0><tr><td rowspan = 3>
<img src=" <? echo $PbigPic; ?> "></td><td>
<table border = 0 width = "100%"><form name = buy action = cart.php method = post>
<input type = hidden value = "<? echo $PNum; ?>">
<tr><td colspan = 2><h3>Price: </h3></td><td><h3><p align = "right">$<? echo $PPrice; ?></h3>
<input type=hidden valu e= $PPrice></td></tr>
<tr><td colspan = 3><? echo $PDescription; ?></td></tr>
<?
echo "</table></td><tr><td><table width=\"100%\" ><tr><td colspan = 2>";
echo "<h3><center>Buy This Item</center></h3></td></tr><tr><td>";
if (($Ptype == "Footspa"|| ($Ptype == "Chair"){
//show the chair select boxes
Show_ChairColor();
echo "</td></tr>";
$SQLOption = "select * from gulf_options where prod_id = $PNum and
option_avail = 1";
$SQLGetOp = mysql_query($SQLOption, $conn) or die ("Couldn't execute query"
echo "<tr><td><table border = 0 cols = 3 width = \"100%\"><tr><td><h4>Options Available</td>";
$x=0;
//get the options and assign the array
while ($row1 = mysql_fetch_array($SQLGetOp)){
$POpNum = $row1["option_id"];
$POpDesc = $row1["option_desc"];
$POptionPrice = $row1["option_price"];
$POpName = $row1["option_name"];
$x++;
echo "<tr><td>$POpName</td><input type =hidden value = $PopName>
<td><center><input type =hidden value = $POptionPrice>
\$$POptionPrice</td>
<td width = 20><input type = checkbox name = Option$x></td></tr>";
}
echo "</table><input type=hidden value = $x>";
How can I bring the data from the form to the SQL statement to store it in the DB table?
Is the table structure correct?
Is there a ready made solution that will accomplish what I need this to do? If so, where can I get it?
TIA
Bastien
There are many ways to skin this cat,
but it still tastes like chicken
I am trying to develop a shopping cart. This cart takes the values from the form and places them into a temp table created to hold the data serverside. The interesting thing is that the form is dynamic. Each product MAY have certain options that only appear when the page for that (well actually it is one page that is dynamically generated with PHP based on an index of products) item is clicked. The challenge is to create the cart table and the SQL statement to allow for the options, and of course not all options have to be choosen.
Here is the script for the table:
Create table $PHPSESSID (
item_sold_id int(10) NOT NULL auto_increment,
date_sold timestamp(14) NOT NULL,
prod_ID int(10) NOT NULL,
prod_name varchar(50), NOT NULL,
distrib_id int(10) default NULL,
quantity_purch tinyint(2) NOT NULL,
option_name varchar (30) NULL,
option_price float (10,2) NULL,
total_price float(10,2) NOT NULL,
PRIMARY KEY (item_sold_id),
UNIQUE KEY item_sold_id(item_sold_id),
KEY item_sold_id_2(item_sold_id)
);
Here is the code that creates the form with the data for the product:
$row = mysql_fetch_array($SQLResult);
$PNum = $row["prod_id"];
$Ptype = $row["prod_type"];
$PName = $row["prod_name"];
$PPrice = $row["prod_price"];
$PDescription = $row["prod_description"];
$PbigPic = $row["gulf_prod_pic"];
mysql_free_result($SQLResult);
?>
<table cols = 2 bgcolor = white border=0><tr><td rowspan = 3>
<img src=" <? echo $PbigPic; ?> "></td><td>
<table border = 0 width = "100%"><form name = buy action = cart.php method = post>
<input type = hidden value = "<? echo $PNum; ?>">
<tr><td colspan = 2><h3>Price: </h3></td><td><h3><p align = "right">$<? echo $PPrice; ?></h3>
<input type=hidden valu e= $PPrice></td></tr>
<tr><td colspan = 3><? echo $PDescription; ?></td></tr>
<?
echo "</table></td><tr><td><table width=\"100%\" ><tr><td colspan = 2>";
echo "<h3><center>Buy This Item</center></h3></td></tr><tr><td>";
if (($Ptype == "Footspa"|| ($Ptype == "Chair"){
//show the chair select boxes
Show_ChairColor();
echo "</td></tr>";
$SQLOption = "select * from gulf_options where prod_id = $PNum and
option_avail = 1";
$SQLGetOp = mysql_query($SQLOption, $conn) or die ("Couldn't execute query"
echo "<tr><td><table border = 0 cols = 3 width = \"100%\"><tr><td><h4>Options Available</td>";
$x=0;
//get the options and assign the array
while ($row1 = mysql_fetch_array($SQLGetOp)){
$POpNum = $row1["option_id"];
$POpDesc = $row1["option_desc"];
$POptionPrice = $row1["option_price"];
$POpName = $row1["option_name"];
$x++;
echo "<tr><td>$POpName</td><input type =hidden value = $PopName>
<td><center><input type =hidden value = $POptionPrice>
\$$POptionPrice</td>
<td width = 20><input type = checkbox name = Option$x></td></tr>";
}
echo "</table><input type=hidden value = $x>";
How can I bring the data from the form to the SQL statement to store it in the DB table?
Is the table structure correct?
Is there a ready made solution that will accomplish what I need this to do? If so, where can I get it?
TIA
Bastien
There are many ways to skin this cat,
but it still tastes like chicken