?

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."

?Topics Author? Date
?multi insert from session??new
vincent 05-05-04 01:29?
?Re: multi insert from session??new
federico 05-06-04 07:04?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??wrote: > > 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']); > } > ?> > style="border-collapse: collapse; border-style: dotted; > border-width: 1" bordercolor="maroon" width="100%"> > > > > > >

ACCOUNTS

> style="border-collapse: collapse" bordercolor="#111111" > width="100%" id="AutoNumber1" height="137"> > > > >
> >
> >
> $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: name="firstname" size="20">
Lastname: name="lastname" size="20"> MI: name="middlename" size="2">'; > > echo "

cellspacing=2 style=\"font-family: Century Gothic; font-size: > 10px\">"; > 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 ' accesskey="P">' . > ''; > } > 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
href=\"array.php?deleteitem=1&iid=".$_SESSION["items"][$i][0]."\">"; > echo $_SESSION["items"][$i][1]."

align=\"right\">".$_SESSION["items"][$i][2]."

align=\"right\">".(float)$_SESSION["items"][$i][3]."

$subtotal
TOTAL colspan=\"3\">" . > "P size=\"7\">".$total."

Provided By
Phorum