?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?multi insert from session
Author:??(203.177.46.---)
Date:???05-05-04 01:29

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']);
}
?>






ACCOUNTS











$basket->show_cart();
?>

// 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 '
' .
'

Firstname:
Lastname: MI: ';

echo "

";
echo "";
$total = 0;
for($i=0; $i<$_SESSION["item_count"]; $i++) {
echo "";
echo "";
echo "";
$subtotal = $_SESSION["items"][$i][2] * $_SESSION["items"][$i][3];
echo "";
echo "";
$total += $subtotal;
}
echo "";

echo '' .
'';
}
else {
echo "

Welcome

";
}
}

function delete_item($id) {
$pos=0;
for($i=0; $i<$_SESSION["item_count"]; $i++) {
if ($_SESSION["items"][$i][0] != $id) {
$_SESSION["items"][$pos] = $_SESSION["items"][$i];
$pos++;
}
}
$_SESSION["item_count"]--;
}

function delete_cart () {
session_destroy();
}
}

function receboHeading() {
echo "WELCOME!!!";
}
?>

HERE is the array2.php




Array2.php



$cnx = mysql_connect($server, $user, $password);
$select_db = mysql_select_db($database, $cnx) or die ("Cannot select database " . mysql_error());

$sql_query = "INSERT FROM tbl_transactions SET firstname='$firstname' , lastname='$lastname', minitial = '$middlename'";

$sql_result = mysql_query($sql_query) or die("Couldn't execute query. " . mysql_error());

echo "Customer: " . strtoupper($lastname) . ", " . ucfirst($firstname) . " " . strtoupper($middlename);
echo '
';

//display the transactions taken place
echo "List of Transactions:
";

$a[0][0] = $_SESSION["items"][$i][1];
$a[0][1] = $_SESSION["items"][$i][2];
$a[0][2] = $_SESSION["items"][$i][3];
$a[0][3] = $total;
$a[0][4] = $_SESSION["item_count"];

foreach($a as $v1) {
foreach ($v1 as $v2) {
print "$v2
\n";
}
}
?>


Item(s)PriceQtySubtotal
";
echo $_SESSION["items"][$i][1]."

".$_SESSION["items"][$i][2]."

".(float)$_SESSION["items"][$i][3]."

$subtotal
TOTAL" .
"P ".$total."
?Re: multi insert from session
Author:??(---.fibertel.com.ar)
Date:???05-06-04 07:04

try this instead:

while(list($key1, $val1) = each($a)) {
while(list($key2, $val2) = each($val1)) {
echo $val2 . "
\n";
}
}


if it doesn't work try

while(list($key1, $val1) = each($a)) {
while(list($key2, $val2) = each($a[$key1])) {
echo $a[$key1][$key2] . "
\n";
}
}

otherwise try to focus on onother part of the code and try to debug it displaying values.

sorry if the problem wasn't there, that what i understand.

Go to Top??|??Go to Topic??|??Threaded View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??

Provided By
Phorum