sorry...I thought you did have ESP. 😃 Here is the code for the addtocart.php:
if (isset($_POST["sel_item_id"])) {
$get_iteminfo_sql = "SELECT product_name FROM product WHERE product_num = '".$_POST["sel_item_id"]."'";
$get_iteminfo_res = mysqli_query($mysqli, $get_iteminfo_sql) or die (mysqli_error($mysqli));
if (mysqli_num_rows($get_iteminfo_res) < 1) {
header("Location: seestore.php");
exit;
} else {
while ($item_info = mysqli_fetch_array($get_iteminfo_res)) {
$product_name = stripslashes($item_info['product_name']);
}
$addtocart_sql = "INSERT INTO shopping_cart
(session_id, sel_item_id, sel_item_qty, date_added)
VALUES ('".$_COOKIE["PHPSESSID"]."',
'".$_POST["sel_item_id"]."',
'".$_POST["sel_item_qty"]."', CURDATE())";
$addtocart_res = mysqli_query($mysqli, $addtocart_sql) or die (mysqli_error($mysqli));
header("Location: showcart.php");
exit;
}
}else{
header("Location: seestore.php");
exit;
}
Here is the code that shows the item:
//validate item
$get_product_sql = "SELECT driver.driver_num as driver_num, product.product_num, product.product_name, product.product_desc, product.product_pic_large, product.product_price, driver.driver_fname, driver.driver_lname
FROM product
LEFT JOIN driver
ON driver.driver_num = product.driver_num
WHERE product.product_num = '".$_GET["product_id"]."'";
$get_product_res = mysqli_query($mysqli, $get_product_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_product_res) <1) {
$display_block = "<p>Invalid item selection.</p>";
} else {
while ($product_info = mysqli_fetch_array($get_product_res)) {
$product_id = $product_info['product_num'];
$product_name = stripslashes($product_info['product_name']);
$product_desc = stripslashes($product_info['product_desc']);
$product_price = $product_info['product_price'];
$product_pic = $product_info['product_pic_large'];
$driver_id = $product_info['driver_num'];
$driver_fname = $product_info['driver_fname'];
$driver_lname = $product_info['driver_lname'];
}
$display_block .="<p><strong>You are Viewing:<br />
<a href=\"seestore.php?driver_id=".$driver_id."\">".$driver_fname." ".$driver_lname."</a>> ".$product_name."</strong></p>
<table cellpadding=\"3\" cellspacing=\"3\">
<tr>
<td valign=\"middle\" align=\"center\">
<img src=\"".$product_pic."\"/></td>
<td valign=\"middle\"><p><strong>Item Number and Name:</strong><br />".
$product_id." - ".$product_name."</p>
<p><strong>Item Description:</strong><br />".$product_desc."</p>
<p><strong>Item Price:</strong><br />".$product_price."</p>
<form method=\"post\" action=\"addtocart.php\">";
//free results
mysqli_free_result($get_product_res);
$display_block .= "
<p><strong>Select Quantity:</strong>
<select name=\"sel_item_qty\">";
for ($i=1; $i<11; $i++) {
$display_block .= "<option value=\"".$i."\">".$i."</option>";
}
$display_block .= "
</select>
<input type=\"hidden\" name=\"sel_item_id\"
value=\"".$_GET["product_id"]."\"/>
<p><input type=\"submit\" name=\"submit\" value=\"Add to Cart\"/></p>
</form>
</td></tr></table>";
}
//close connection to mySQL
mysqli_close($mysqli);
?>
I've been over and over the code...so I'm probably blinded by now. However, my main confusion comes from why sometimes it does work (by just pulling one)...and sometimes it pulls 12 specific ones. When I check the database it shows for these 12 that the sel_item_id is 0. But...it pulls the correct product_num. Ugh...