hi
im creating a script for our small store wher it can handle daily transaction. it is process by a session. now i want to have it insert in a mysql database and display the inserted transaction.
i try the foreach() function but nothing is displayed.
here is my scripts. when i click the page, the array2.php will insert to the mysql database the pid, name, and the quantity, pls help, i dont know how to.
session_start();
$basket=new basket();
/* catch cart actions */
if (isset($_GET['deletecart']) && $_GET['deletecart'])
$basket->delete_cart();
if (isset($_GET['deleteitem']) && $_GET['deleteitem'])
$basket->delete_item($_GET['iid']);
if (isset($_GET['addtocart']) && $_GET['addtocart']) {
$basket->add_item($_GET['iid'],$_GET['iname'],$_GET['iprice']);
}
?>
// class basket cart class
// ang main configuration gid ka shopping cart
class basket {
// constructor
function basket () {
// set starting count
if (!isset($_SESSION["item_count"]))
$_SESSION["item_count"] = 0;
}
function add_item ($id,$name,$price) {
if ($_SESSION["item_count"] > 0) {
$found=false;
for($i=0; $i<$_SESSION["item_count"]; $i++) {
if ($_SESSION["items"][$i][0] == $id) {
$_SESSION["items"][$i][3]++;
$found=true;
}
}
if (!$found) {
// add new item to existing basket
$_SESSION["items"][$_SESSION["item_count"]] = array($id,$name,$price,1);
$_SESSION["item_count"]++;
}
} else {
// add first item to basket
$_SESSION["items"][0] = array($id,$name,$price,1);
$_SESSION["item_count"]=1;
}
}
function show_cart() {
if (isset($_SESSION["item_count"]) && $_SESSION["item_count"] > 0) {
echo '