I have a shopping cart that works pretty good. the category page links perfectly to the more info page, and from there I can add to cart and I have the code working great. My new problem is that I need to create options for specific items.
When a user is on the moreinfo.php, the form gathers the name and price of the item and dumps it into the cart, however, i'd like to add a step there. I'd like to create a customize.php page where the user will click, "add to order" and it will take them to a page that displays required options to customize that item. from the customize page, they can then click "Add to order" and it will dump that data into the cart.php file.
My code for moreinfo.php (which works perfectly how it is)
<?php
require("database.php"); //connect to the database
if(isset($_GET['id'])){
$id = $_GET['id'];
}
$result = mysqli_query($con,"SELECT * FROM menuitem WHERE id='$id' LIMIT 1");
if (!$result) {
printf("Error: %s\n", mysqli_error($con));// Displays the error that mysql will generate if syntax is not correct.
exit();
}
//DYNAMIC PHP PULLING IN THE DATA AND SPITTING OUT THE RESULTS
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$description = $row['description'];
$picturepath = $row['picturepath'];
$name = $row['name'];
$price = $row['price'];
$keywords = $row['keywords'];
$dynamiclist = '<table align="center" width="60%" border="0" cellspacing="5" cellpadding="8">
<tr height="150"></tr>
<tr>
<td width="30% valign="top" align="center"><img style="border: #66cc33 5px solid;" src=" ' .$picturepath . '" height="200" width="200" border="1"/></td>
<td width="70%" valign="top" align="left"> <br />' . $name . ' <br /><br />$' . $price . '<br /><br /><font>Description:</font><br /> ' . $description . ' <br /><br /><br />
<form id="form1" name="form1" method="post" action="customize.php">
<input type="hidden" name="pid" id="pid" value=" ' . $name . ' - $' . $price . ' "/>
<input type="submit" name="button" id="button" value="Add to Order"/>
</form>
</td>
</tr>
<tr align="center"><td><a href="cart.php">View Your Order</a></td></tr>
</table>';
echo $dynamiclist;
}
mysqli_close($con); //close the db connection
?>
Now, I'd like to link this to customize.php where the user can make choices. In my MySQL table, I have a column "keywords". This is a set of 4 or 5 words that I'd like the dropdown optgroup to display the items options. Here is the code I have tried that is not working, but I might be on the right track.
<?php
require("database.php"); //connect to the database
session_start();
if(isset($_GET['pid'])){
$id = $_GET['pid'];
}
$result = mysqli_query($con,"SELECT * FROM menuitem WHERE id='$id'");
if (!$result) {
printf("Error: %s\n", mysqli_error($con));// Displays the error that mysql will generate if syntax is not correct.
exit();
}
//DYNAMIC PHP PULLING IN THE DATA AND SPITTING OUT THE RESULTS
$option = '';
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$description = $row['description'];
$picturepath = $row['picturepath'];
$name = $row['name'];
$price = $row['price'];
$keywords = $row['keywords'];
$dynamiclist = '<form id="form1" name="form1" method="post" action="cart.php">
<select name="pid" id="pid">
<option value="'. $keywords .'"></option>
</select><br>
<input type="hidden" name="pid" id="pid" value=" ' . $name . ' - $' . $price . ' "/>
<input type="submit" value="SUBMIT THIS!">
</form>';
echo $dynamiclist;
}
mysqli_close($con); //close the db connection
?>
Does any of this look correct?