Hello, I've been struggling with this for ages now, so it's time I asked for
help. I'm setting up a shopping cart in Flash, using PHP to process the
information and store/retrieve from a MySQL database. I can add items to the
cart and display them, no problem, however I can't work out how to update the
quantities of items in the cart (other than adding more of that item from the
item page). I can do it using just PHP, but I can't work out how I can get
ActionScript to send the same string as a HTML form. I'm using a HTML form that
looks like this as a template:
echo " <tr>
<td align=\"left\">{$row} {$row} {$row}</td>
<td align=\"left\">{$row}</td>
<td align=\"right\">\${$row}</td>
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty}]\"
value=\"{$_SESSION]}\" /></td>
<td align=\"right\">$" . number_format ($subtotal, 2) . "</td>
</tr>\n";
which returns the information submitted back to the same page, where the
information would be updated based on what the user had entered, something like
this:
if (isset ($_POST)) {
foreach ($_POST as $key => $value) {
if ( ($value == 0) AND (is_numeric ($value)) ) {
unset ($_SESSION);
} elseif ( is_numeric ($value) AND ($value > 0) ) {
$_SESSION = $value;
}
}
}
My question is, how can I put together a string, based on the values in input
text boxes (which display the current quantity, which may or may not be changed
by the user) in ActionScript, that a PHP script like the one above would
understand? I'm using LoadVars for all my other PHP/Flash integration needs.
It's screwing my head up trying to work out how to make each quantity variable
reference the correct product, and do it the correct syntax for the query to
work. My actionscript is currently looking something like this:
///////////////////LOAD VARS//////////////////////////
cartOut = new LoadVars();
cartIn = new LoadVars();
updateOut = new LoadVars();
updateIn = new LoadVars();
iProductID_array = new Array();
qty_array = new Array();
sProductName_array = new Array();
sStoreID_array = new Array();
subTotal_array = new Array();
function displayCart() {
var n = cartIn.n;
var i = 0;
var y = 24;
while (i<n) {
newMc = _level0.content_mc.table_mc;
newMc._y += y;
newMc.itemreftext = sStoreID_array;
newMc.itemnametext = sProductName_array;
newMc.quantitytext = qty_array;
newMc.pricetext = "?"+subTotal_array;
i++;
y += 23;
newMc._visible = 1;
table_mc.cartTotalBox._y = newMc._y+23;
}
}
cartIn.onLoad = function(success) {
var n = cartIn.n;
var i = 0;
if (n != 0) {
while (i<n) {
iProductID_array = cartIn;
sStoreID_array = cartIn;
sProductName_array = cartIn;
qty_array = cartIn;
subTotal_array = cartIn;
duplicateMovieClip(table_mc.tableRow_mc, "tableRow"+i+"_mc", i);
i++;
}
buttons_mc._visible = 1;
displayCart();
table_mc.cartTotal = "?"+cartIn.cartTotal;
} else if (n == 0) {
emptyCart_mc._visible = 1;
buttons_mc._visible = 0;
}
};
updateIn.onLoad = function(success) {
var n = cartIn.n;
var i = 0;
if (n != 0) {
while (i<n) {
qty_array = updateIn;
subTotal_array = updateIn;
i++;
}
displayCart();
table_mc.cartTotal = "?"+updateIn.cartTotal;
} else {
emptyCart_mc._visible = 1;
buttons_mc._visible = 0;
table_mc._visible = 0;
}
};
cartOut.sendAndLoad("../view_cart.php", cartIn, "POST");
///////////////////////BUTTONS////////////////////////////////
_level0.content_mc.buttons_mc.updatecartbtn_mc.onRelease = function() {
updateMc = _level0.content_mc.table_mc;
updateOut.num = 1;
updateOut.prodID = iProductID_array;
updateOut.qty = updateMc.quantitytext;
updateOut.request = "update";
updateOut.sendAndLoad("../view_cart.php", cartIn, "POST");
};
feed_me - 24 Mar 2006 19:38 GMT
Anyone? Go on... I'm sure someone has an idea...? I don't want a full solution, just an idea of PHP $_POST query syntax so I can work the rest out...
Motion Maker - 27 Mar 2006 03:37 GMT
>>My question is, how can I put together a string, based on the values in
>>input
[quoted text clipped - 3 lines]
>>understand? I'm using LoadVars for all my other PHP/Flash integration
>>needs
The example in Flash help will do the trick for learning this -
http://livedocs.macromedia.com/flash/8/main/00002336.html
On the PHP side the variables in the send_lv will be in $_REQUEST ready for
exploitation.

Signature
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
Hello, I've been struggling with this for ages now, so it's time I asked for
help. I'm setting up a shopping cart in Flash, using PHP to process the
information and store/retrieve from a MySQL database. I can add items to the
cart and display them, no problem, however I can't work out how to update
the
quantities of items in the cart (other than adding more of that item from
the
item page). I can do it using just PHP, but I can't work out how I can get
ActionScript to send the same string as a HTML form. I'm using a HTML form
that
looks like this as a template:
echo " <tr>
<td align=\"left\">{$row} {$row} {$row}</td>
<td align=\"left\">{$row}</td>
<td align=\"right\">\${$row}</td>
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty}]\"
value=\"{$_SESSION]}\" /></td>
<td align=\"right\">$" . number_format ($subtotal, 2) . "</td>
</tr>\n";
which returns the information submitted back to the same page, where the
information would be updated based on what the user had entered, something
like
this:
if (isset ($_POST)) {
foreach ($_POST as $key => $value) {
if ( ($value == 0) AND (is_numeric ($value)) ) {
unset ($_SESSION);
} elseif ( is_numeric ($value) AND ($value > 0) ) {
$_SESSION = $value;
}
}
}
My question is, how can I put together a string, based on the values in
input
text boxes (which display the current quantity, which may or may not be
changed
by the user) in ActionScript, that a PHP script like the one above would
understand? I'm using LoadVars for all my other PHP/Flash integration needs.
It's screwing my head up trying to work out how to make each quantity
variable
reference the correct product, and do it the correct syntax for the query to
work. My actionscript is currently looking something like this:
///////////////////LOAD VARS//////////////////////////
cartOut = new LoadVars();
cartIn = new LoadVars();
updateOut = new LoadVars();
updateIn = new LoadVars();
iProductID_array = new Array();
qty_array = new Array();
sProductName_array = new Array();
sStoreID_array = new Array();
subTotal_array = new Array();
function displayCart() {
var n = cartIn.n;
var i = 0;
var y = 24;
while (i<n) {
newMc = _level0.content_mc.table_mc;
newMc._y += y;
newMc.itemreftext = sStoreID_array;
newMc.itemnametext = sProductName_array;
newMc.quantitytext = qty_array;
newMc.pricetext = "?"+subTotal_array;
i++;
y += 23;
newMc._visible = 1;
table_mc.cartTotalBox._y = newMc._y+23;
}
}
cartIn.onLoad = function(success) {
var n = cartIn.n;
var i = 0;
if (n != 0) {
while (i<n) {
iProductID_array = cartIn;
sStoreID_array = cartIn;
sProductName_array = cartIn;
qty_array = cartIn;
subTotal_array = cartIn;
duplicateMovieClip(table_mc.tableRow_mc, "tableRow"+i+"_mc", i);
i++;
}
buttons_mc._visible = 1;
displayCart();
table_mc.cartTotal = "?"+cartIn.cartTotal;
} else if (n == 0) {
emptyCart_mc._visible = 1;
buttons_mc._visible = 0;
}
};
updateIn.onLoad = function(success) {
var n = cartIn.n;
var i = 0;
if (n != 0) {
while (i<n) {
qty_array = updateIn;
subTotal_array = updateIn;
i++;
}
displayCart();
table_mc.cartTotal = "?"+updateIn.cartTotal;
} else {
emptyCart_mc._visible = 1;
buttons_mc._visible = 0;
table_mc._visible = 0;
}
};
cartOut.sendAndLoad("../view_cart.php", cartIn, "POST");
///////////////////////BUTTONS////////////////////////////////
_level0.content_mc.buttons_mc.updatecartbtn_mc.onRelease = function() {
updateMc = _level0.content_mc.table_mc;
updateOut.num = 1;
updateOut.prodID = iProductID_array;
updateOut.qty = updateMc.quantitytext;
updateOut.request = "update";
updateOut.sendAndLoad("../view_cart.php", cartIn, "POST");
};
feed_me - 27 Mar 2006 10:32 GMT
Hey, Thanks for that, but I'm okay with that bit. My question really (I didn't
ask it very well before), is with this bit:
foreach ($_POST as $key => $value)
I am not understanding how you have more than one $_POST? What is appended to
each to identify it as different to the last? I know it comes from here:
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty}]\"
value=\"{$_SESSION]}\" /></td>
in the php/html form, so what I really want to know is the correct syntax to
build the same query via actionscript. Do I need to make the UpdateOut.qty
variable a more complex string, or is it the name of the variable (e.g.
UpdateOut.qty for example)?
Motion Maker - 27 Mar 2006 12:58 GMT
>>I am not understanding how you have more than one $_POST?
That seems to be a PHP questions and there can be only one super global such
as $_POST per script running. Flash can make as many requests to a server
side script or scripts as you need. I could call the same script multiple
times, with different variable values to direct the script to do different
tasks. Regardless, for each request of a server script all the variables
would be in $_REQUEST (I do not use $_POST so that one someone else would
need to comment on).
As for the $_SESSION variables, Flash cannot access those. The server side
script would read and write those. Flash could have the $_SESSION variable
key names either from a LoadVars converstation or user interaction with the
Flash movie.
>>Do I need to make the UpdateOut.qty variable a more complex string, or is
>>it the name of the variable (e.g.
UpdateOut.qty for example)?
It appears to me you need to have the server script send the $_SESSION
variable to the Flash movie and use it in a text field.

Signature
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
Hey, Thanks for that, but I'm okay with that bit. My question really (I
didn't
ask it very well before), is with this bit:
foreach ($_POST as $key => $value)
I am not understanding how you have more than one $_POST? What is appended
to
each to identify it as different to the last? I know it comes from here:
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty}]\"
value=\"{$_SESSION]}\" /></td>
in the php/html form, so what I really want to know is the correct syntax
to
build the same query via actionscript. Do I need to make the UpdateOut.qty
variable a more complex string, or is it the name of the variable (e.g.
UpdateOut.qty for example)?