I wish to replace [[ with [
AND
]] with ] in an associative array .
How can I do this?
I wish to replace [[ with [
AND
]] with ] in an associative array .
How can I do this?
J.O. Aho <user@example.net> wrote:
: On 3/2/23 13:44, The Doctor wrote:
: A wild guess, this still to do with your json, which you have asked help
: with quite often.
: > I wish to replace [[ with [
: >
: > AND
: >
: > ]] with ] in an associative array .
: Don't store objects as an array and place those arrays in an array.
: Create an object and place the object into the array which is part of
: your main-object.
All right. Even in a recursive loop?
: > How can I do this?
: If you just look at a string, string replace could work quite well to do
: this
: str_replace('[[','[',$str);
Woth a try.
Arno Welzel <usenet@arnowelzel.de> wrote:
: The Doctor, 2023-03-02 13:44:
: > I wish to replace [[ with [
: >
: > AND
: >
: > ]] with ] in an associative array .
: >
: > How can I do this?
: What do you mean with "in an associative array"? The values? The keys?
: If you want to replace the characters in values:
: <?php
: $array = [
: 'value 1' => '[[something 1',
: 'value 2' => 'something 2]]',
: ];
: // Output array as it was before
: print_r($array);
: foreach($array as $key => $value)
: {
: $array[$key] = str_replace(
: [ '[[', ']]' ],
: [ '[', ']' ],
: $value
: );
: }
: // Output as it was afterwards
: print_r($array);
What is happening is that the arrauy is being formed by a subarray
and the end product is seeing a [[ at the start and a ]]
at the end when it should be seeing a [ at the start and a ] at the end.
What is happening is that the arrauy is being formed by a subarray
and the end product is seeing a [[ at the start and a ]]
at the end when it should be seeing a [ at the start and a ] at the end.
Arno Welzel <usenet@arnowelzel.de> wrote:
: The Doctor, 2023-03-04 06:19:
: [...]
: > What is happening is that the arrauy is being formed by a subarray
: > and the end product is seeing a [[ at the start and a ]]
: > at the end when it should be seeing a [ at the start and a ] at the end.
: Then don't create a subarray!
: Again: if you need objects, then create objects and not arrays!
J.A AHo and Arno ,
2 Problems here
a) Converting a page from a programmer that did not use classes
b) Web pages that actually you can search adn
the results give you not what you want.
If you 2 had quality web pages on PHP
programming , you should be up there and not the pages
Google, yahoo et al as showing.
On 3/4/23 15:57, The Doctor wrote:
a) Converting a page from a programmer that did not use classes
Then you need to rewrite things, how many weeks hasn't you spent on
trying to get a proper json of the mess of arrays. Doing it right and rewrite, I think you would have finished a month ago already.
Take a look at the following code, test it too and you see the benefit https://pastebin.com/yJC9DJWs
If you rewrite things now, you will save time and efforts in the future, specially if there comes changes to the API.
On 3/5/23 00:58, The Doctor wrote:
J.O. Aho <user@example.net> wrote:
: https://pastebin.com/bF6bZseu
: Keep in mind nothin is a 100% solution for your issue as I haven't
: bothered really go into the API that is used but just a bit based on
: your posts in this group.
: And please, what ever you do, don't go with the str_replace, it's not
: the solution to your issue, it will just make things a lot harder to
: maintain.
Actually the class approach works better.
That's good, just tweak it to fit your user case, just don't forget
validate the input data.
Too bad Google does not pick that up
in their searches for JSON>
Much depends on the requirements and what the json is used for, say
sending data between angular and php, then the coder is usually in
control of both front end and backend and can use what ever json format
they want, but it's different when you have to follow an API, but
usually you can get support from the API owner and payment services tend
to also do a verification round before letting you to use production
grade transactions.
--
//Aho
J.O. Aho <user@example.net> wrote:
: https://pastebin.com/bF6bZseu
: Keep in mind nothin is a 100% solution for your issue as I haven't
: bothered really go into the API that is used but just a bit based on
: your posts in this group.
: And please, what ever you do, don't go with the str_replace, it's not
: the solution to your issue, it will just make things a lot harder to
: maintain.
Actually the class approach works better.
Too bad Google does not pick that up
in their searches for JSON>
In article <k6i6l8FksscU2@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
On 3/5/23 00:58, The Doctor wrote:
J.O. Aho <user@example.net> wrote:
: https://pastebin.com/bF6bZseu
: Keep in mind nothin is a 100% solution for your issue as I haven't
: bothered really go into the API that is used but just a bit based on
: your posts in this group.
: And please, what ever you do, don't go with the str_replace, it's not
: the solution to your issue, it will just make things a lot harder to
: maintain.
Actually the class approach works better.
That's good, just tweak it to fit your user case, just don't forget
validate the input data.
Too bad Google does not pick that up
in their searches for JSON>
Much depends on the requirements and what the json is used for, say
sending data between angular and php, then the coder is usually in
control of both front end and backend and can use what ever json format
they want, but it's different when you have to follow an API, but
usually you can get support from the API owner and payment services tend
to also do a verification round before letting you to use production
grade transactions.
A good article can be written about this.
I wish to replace [[ with [
AND
]] with ] in an associative array .
How can I do this?
--
Member - Liberal International This is doc...@nk.ca Ici doc...@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Only an evil person could punish someone for doing good, and only an evil ideology could allow it. -unknown Beware https://mindspring.com
The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
: J.O. Aho <user@example.net> wrote:
: : On 3/5/23 01:52, The Doctor wrote:
: : > In article <k6i6l8FksscU2@mid.individual.net>,
: : > J.O. Aho <user@example.net> wrote:
: : >> On 3/5/23 00:58, The Doctor wrote:
: : >>> J.O. Aho <user@example.net> wrote:
: : >>
: : >>> : https://pastebin.com/bF6bZseu
: : >>> : Keep in mind nothin is a 100% solution for your issue as I haven't : : >>> : bothered really go into the API that is used but just a bit based on
: : >>> : your posts in this group.
: : >>>
: : >>> : And please, what ever you do, don't go with the str_replace, it's not
: : >>> : the solution to your issue, it will just make things a lot harder to
: : >>> : maintain.
: : >>>
: : >>>
: : >>> Actually the class approach works better.
: : >>
: : >> That's good, just tweak it to fit your user case, just don't forget
: : >> validate the input data.
: : >>
: : >>
: : >>> Too bad Google does not pick that up
: : >>> in their searches for JSON>
: : >>
: : >> Much depends on the requirements and what the json is used for, say
: : >> sending data between angular and php, then the coder is usually in
: : >> control of both front end and backend and can use what ever json format
: : >> they want, but it's different when you have to follow an API, but
: : >> usually you can get support from the API owner and payment services tend
: : >> to also do a verification round before letting you to use production
: : >> grade transactions.
: : >>
: : >
: : > A good article can be written about this.
: : Great, post the link when you have written it ;)
: : It's about time, to write a good example that make sense without bad
: : coding and then host and promote the page, not everyone is prepared to
: : do that.
: : Sadly we see a lot of cheap cut the corner stuff out on the net, much
: : for people have sample with simple structures so arrays works ok, but
: : that is much based on the quality of the education they had. For example : : there is a country that spits out 2 million CS each year, many of them
: : have a skills level not much than general high school students
: : programing knowledge level. Should also note that there are really good
: : programmers from that country too.
: : The main thing is that you get forward on your project.
: Wait until you see the nightmare in bureaucracy.
Other nightmare, I might have to write a preview page.
Actually the class approach works better.
Too bad Google does not pick that up
in their searches for JSON>
Arno Welzel <usenet@arnowelzel.de> wrote:
: The Doctor, 2023-03-05 00:58:
: [...]
: > Actually the class approach works better.
: >
: > Too bad Google does not pick that up
: > in their searches for JSON>
: Well - programming is about to *learn* how to do things and not about
: "look at Google if there is a solution for it".
Too bad all roads pint to Google.
Arno Welzel <usenet@arnowelzel.de> wrote:
: The Doctor, 2023-03-09 02:25:
: > Arno Welzel <usenet@arnowelzel.de> wrote:
: > : The Doctor, 2023-03-05 00:58:
: >
: > : [...]
: > : > Actually the class approach works better.
: > : >
: > : > Too bad Google does not pick that up
: > : > in their searches for JSON>
: >
: > : Well - programming is about to *learn* how to do things and not about
: > : "look at Google if there is a solution for it".
: >
: > Too bad all roads pint to Google.
: No in my life. I started learning programming long before Google even
: existed.
And that is a very good thing!
I wish to replace [[ with [
AND
]] with ] in an associative array .
How can I do this?
--
Member - Liberal International This is doc...@nk.ca Ici doc...@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Only an evil person could punish someone for doing good, and only an evil ideology could allow it. -unknown Beware https://mindspring.com
On Thursday, March 2, 2023 at 2:47:42=E2=80=AFPM UTC+2, The Doctor wrote:
I wish to replace [[ with [=20ideology could allow it. -unknown Beware https://mindspring.com
=20
AND=20
=20
]] with ] in an associative array .=20
=20
How can I do this?=20
=20
--=20
Member - Liberal International This is doc...@nk.ca Ici doc...@nk.ca=20
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist r= >ising!=20
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=3D94= >a1f39b=20
Only an evil person could punish someone for doing good, and only an evil=
The Doctor, 2023-03-05 00:58:
[...]
Actually the class approach works better.
Too bad Google does not pick that up
in their searches for JSON>
Well - programming is about to *learn* how to do things and not about
"look at Google if there is a solution for it".
--
Arno Welzel
https://arnowelzel.de
In article <k6shf2F8l9lU1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
The Doctor, 2023-03-05 00:58:
[...]
Actually the class approach works better.
Too bad Google does not pick that up
in their searches for JSON>
Well - programming is about to *learn* how to do things and not about
"look at Google if there is a solution for it".
Bureaucracy said they are doing the job, but the customer is not happy.
Can I create an intermediary state
so just just before the customer hits the pay button,
they are review what they are sending?
--
Arno Welzel
https://arnowelzel.de
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b >All words are devalued in the mouth of the liar. -unknown Beware >https://mindspring.com
In article <u0l3ip$1e4l$2@gallifrey.nk.ca>,
The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
In article <k6shf2F8l9lU1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
The Doctor, 2023-03-05 00:58:
[...]
Actually the class approach works better.
Too bad Google does not pick that up
in their searches for JSON>
Well - programming is about to *learn* how to do things and not about
"look at Google if there is a solution for it".
Bureaucracy said they are doing the job, but the customer is not happy.
Can I create an intermediary state
so just just before the customer hits the pay button,
they are review what they are sending?
Try to pass a json from 1 form to another.
On 4/13/23 00:45, The Doctor wrote:
In article <u0l3ip$1e4l$2@gallifrey.nk.ca>,
The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
In article <k6shf2F8l9lU1@mid.individual.net>,
Arno Welzel <usenet@arnowelzel.de> wrote:
The Doctor, 2023-03-05 00:58:
[...]
Actually the class approach works better.
Too bad Google does not pick that up
in their searches for JSON>
Well - programming is about to *learn* how to do things and not about
"look at Google if there is a solution for it".
Bureaucracy said they are doing the job, but the customer is not happy.
Can I create an intermediary state
so just just before the customer hits the pay button,
they are review what they are sending?
Try to pass a json from 1 form to another.
This is why you have session cookies, no point of passing data from a
form to another.
--
//Aho
In article J.O. Aho <user@example.net> wrote:
Try to pass a json from 1 form to another.
This is why you have session cookies, no point of passing data from a
form to another.
I have
<?=session_start();
error_reporting(E_ALL);
So I need to add a specific cookie/ token ?
On 4/13/23 13:50, The Doctor wrote:
In article J.O. Aho <user@example.net> wrote:
Try to pass a json from 1 form to another.
This is why you have session cookies, no point of passing data from a
form to another.
I have
<?=session_start();
error_reporting(E_ALL);
So I need to add a specific cookie/ token ?
You just use the $_SESSION to store and fetch data as I mentioned in my
post from 7th of March.
The page you posted the values to:
$_SESSION['serialized_order'] = serialize($order);
and on the page where you need all the data:
$order = unserialize($_SESSION['serialized_order']);
if you need to modify the data, then read it from the session and then
store it back to the session.
Keep in mind the session data is never sent to the browser, so the user
can't adjust the data on their side.
--
//Aho
95% there.
Now I have split the form successfully I need to get
the cartitem in a printable format.
So given when I have worked on
<?=session_start();
error_reporting(E_ALL);
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/css.css"/>
<link rel="stylesheet" type="text/css" href="css/css2.css"/>
</head>
<?php
if(!empty($_SESSION['sessiondata'])){
}
<?php
$myObj = [];
$storevalues= array();
$cartarray= array();
$cart= array();
$contact1=array();
$contact_details=array();
$shipping1=array();
$shipping_details=array();
$billing1=array();
$billing_details=array();
$arr2 =array();
class Storevs{
}
class Item
{
}
class TaxItem
{
}
class CartItem
{
public $items;
public $subtotal;
public $tax;
};
class Contact
{
}
class Shipping
{
}
class Billing
{
}
$items_count = 0;
$newsubtotal = 0;
$subtotal = 0;
$arr = array();
if (isset($_POST["submit"])){
$storevalues=(array) $storev;
}
if (isset($_POST["submit"])){
$cartitem= new CartItem();
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
$item = new Item();
$item->url = "https://image";
$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $value;
$cartitem->items[] = $item;
}
}
$cartitem->subtotal = ($_POST['charge_total']/1.05);
$taxItem = new TaxItem();
$taxItem->amount = (($_POST['charge_total']/1.05) * 0.05); $taxItem->description = "GST";
$taxItem->rate = "5.00";
$cartitem->tax = $taxItem;
$cart= (array) $cartitem ;
$cartarray = array( "cart" => $cartitem);
}
if (isset($_POST["submit"])){
$contact=new Contact;
$contact1= (array) $contact ;
$contact_details=array ( "contact_details" => $contact1 );
}
if (isset($_POST["submit"])){
$shipping = new Shipping;
$shipping1 = (array) $shipping;
$shipping_details=array( "shipping_details" => $shipping1 );
}
if (isset($_POST["submit"])){
$billing = new Billing;
$billing_details=array( "billing_details" => $billing1 );
}
$_SESSION['arr'] = serialize($arr);
$_SESSION['serialized_Obj'] = serialize($myObj);
<body>
<form action="https://www.nk.ca/pdsolutions/step5b.php" method="post" >
<h2> Please review your order!</h2>
<?php
echo "<br /><br />";
echo "<h3> Contact Information </h3>";
echo "<br /> My name is " . $contact->first_name . " " . $contact->last_name . "<br />";
echo "My E-mail address is " . $contact->email . " <br />";
echo "You can call me at " . $contact->phone . " <br /> <br />";
echo "<h3> Billing Information </h3>";
echo "<br /> Address :" . $billing->address_1 . "<br />";
echo $billing->address_2 . "<br />";
echo "Municipality:" . $billing->city . "<br />";
echo "Province:" . $billing->province . "<br />";
echo "Postal Code:" . $billing->postal_code . "<br /><br />";
echo "<h3> Shipping Information </h3>";
echo "<br /> Address :" . $shipping->address_1 . "<br />";
echo $shipping->address_2 . "<br />";
echo "Municipality:" . $shipping->city . "<br />";
echo "Province:" . $shipping->province . "<br />";
echo "Postal Code:" . $shipping->postal_code . "<br /><br />";
echo "<h3> Course Information </h3>";
<input type="submit" value="Place Your Order" name="submit" id="submit" >
<input onclick="history.back()" type="reset" value="Clear the Form" id="reset" />
</form>
</body>
</html>
On 4/14/23 03:12, The Doctor wrote:
95% there.
Now I have split the form successfully I need to get
the cartitem in a printable format.
So given when I have worked on
<?=session_start();
error_reporting(E_ALL);
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, >maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/css.css"/>
<link rel="stylesheet" type="text/css" href="css/css2.css"/>
</head>
<?php
if(!empty($_SESSION['sessiondata'])){
}
<?php
$myObj = [];
$storevalues= array();
$cartarray= array();
$cart= array();
$contact1=array();
$contact_details=array();
$shipping1=array();
$shipping_details=array();
$billing1=array();
$billing_details=array();
$arr2 =array();
Try to avoid all these arrays, they don't make life easier.
class Storevs{
}
class Item
{
}
class TaxItem
{
}
class CartItem
{
public $items;
public $subtotal;
public $tax;
};
class Contact
{
}
class Shipping
{
}
class Billing
{
}
Don't define the classes here, then you need to do it each file you use,
you create an php script that just includes the classes and then use include >https://www.php.net/manual/en/function.include.php
$items_count = 0;
$newsubtotal = 0;
$subtotal = 0;
$arr = array();
if (isset($_POST["submit"])){
$storevalues=(array) $storev;
}
if (isset($_POST["submit"])){
$cartitem= new CartItem();
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
prices shouldn't be hard coded, you don't want to change the code just
for the price went up due of inflation, you change the price in a
database of some sort.
$item = new Item();
$item->url = "https://image";
$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $value;
$cartitem->items[] = $item;
}
}
$cartitem->subtotal = ($_POST['charge_total']/1.05);
Hey, this ain't a value you can trust, you need to go trough all the
items in the cart, check up the price for each item and calculate the total.
Say a user with one of the many browser plugins that allows you to
modify post data, the user just adds all the items it wants and then
change the value for charge_total to 0, please calculate how pissed your
boss will be.
$taxItem = new TaxItem();
$taxItem->amount = (($_POST['charge_total']/1.05) * 0.05);
$taxItem->description = "GST";
$taxItem->rate = "5.00";
$cartitem->tax = $taxItem;
$cart= (array) $cartitem ;
$cartarray = array( "cart" => $cartitem);
}
if (isset($_POST["submit"])){
$contact=new Contact;
$contact1= (array) $contact ;
$contact_details=array ( "contact_details" => $contact1 );
}
if (isset($_POST["submit"])){
$shipping = new Shipping;
$shipping1 = (array) $shipping;
$shipping_details=array( "shipping_details" => $shipping1 );
}
if (isset($_POST["submit"])){
$billing = new Billing;
$billing_details=array( "billing_details" => $billing1 );
}
$_SESSION['arr'] = serialize($arr);
$_SESSION['serialized_Obj'] = serialize($myObj);
<body>
<form action="https://www.nk.ca/pdsolutions/step5b.php" method="post" >
<h2> Please review your order!</h2>
<?php
echo "<br /><br />";
why do you echo the html code? leave those outside the php code, you can
have multiple <?php ?> in a page.
echo "<h3> Contact Information </h3>";
echo "<br /> My name is " . $contact->first_name . " " . >$contact->last_name . "<br />";
echo "My E-mail address is " . $contact->email . " <br />";
echo "You can call me at " . $contact->phone . " <br /> <br />";
echo "<h3> Billing Information </h3>";
echo "<br /> Address :" . $billing->address_1 . "<br />";
echo $billing->address_2 . "<br />";
echo "Municipality:" . $billing->city . "<br />";
echo "Province:" . $billing->province . "<br />";
echo "Postal Code:" . $billing->postal_code . "<br /><br />";
echo "<h3> Shipping Information </h3>";
echo "<br /> Address :" . $shipping->address_1 . "<br />";
echo $shipping->address_2 . "<br />";
echo "Municipality:" . $shipping->city . "<br />";
echo "Province:" . $shipping->province . "<br />";
echo "Postal Code:" . $shipping->postal_code . "<br /><br />";
echo "<h3> Course Information </h3>";
Here you use a foreach loop that goes over the cart items, of course you
need to deserialize the $_SESSION['serialized_Obj']. >https://www.php.net/manual/en/control-structures.foreach.php
Form" id="reset" /><input type="submit" value="Place Your Order" name="submit" id="submit" > >> <input onclick="history.back()" type="reset" value="Clear the
</form>
</body>
</html>
--
//Aho
I wish to replace [[ with [
AND
]] with ] in an associative array .
How can I do this?
--
Member - Liberal International This is doc...@nk.ca Ici doc...@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b
Only an evil person could punish someone for doing good, and only an evil ideology could allow it. -unknown Beware https://mindspring.com
On Thursday, March 2, 2023 at 2:47:42=E2=80=AFPM UTC+2, The Doctor wrote:
I wish to replace [[ with [=20ideology could allow it. -unknown Beware https://mindspring.com
=20
AND=20
=20
]] with ] in an associative array .=20
=20
How can I do this?=20
=20
--=20
Member - Liberal International This is doc...@nk.ca Ici doc...@nk.ca=20
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist r= >ising!=20
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=3D94= >a1f39b=20
Only an evil person could punish someone for doing good, and only an evil=
In article <k9th4vFauniU1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
On 4/14/23 03:12, The Doctor wrote:
95% there.
Now I have split the form successfully I need to get
the cartitem in a printable format.
So given when I have worked on
<?=session_start();
error_reporting(E_ALL);
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, >>maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="css/css.css"/>
<link rel="stylesheet" type="text/css" href="css/css2.css"/>
</head>
<?php
if(!empty($_SESSION['sessiondata'])){
}
<?php
$myObj = [];
$storevalues= array();
$cartarray= array();
$cart= array();
$contact1=array();
$contact_details=array();
$shipping1=array();
$shipping_details=array();
$billing1=array();
$billing_details=array();
$arr2 =array();
Try to avoid all these arrays, they don't make life easier.
class Storevs{
}
class Item
{
}
class TaxItem
{
}
class CartItem
{
public $items;
public $subtotal;
public $tax;
};
class Contact
{
}
class Shipping
{
}
class Billing
{
}
Don't define the classes here, then you need to do it each file you use, >>you create an php script that just includes the classes and then use include >>https://www.php.net/manual/en/function.include.php
$items_count = 0;
$newsubtotal = 0;
$subtotal = 0;
$arr = array();
if (isset($_POST["submit"])){
$storevalues=(array) $storev;
}
if (isset($_POST["submit"])){
$cartitem= new CartItem();
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
prices shouldn't be hard coded, you don't want to change the code just
for the price went up due of inflation, you change the price in a
database of some sort.
$item = new Item();
$item->url = "https://image";
$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $value;
$cartitem->items[] = $item;
}
}
$cartitem->subtotal = ($_POST['charge_total']/1.05);
Hey, this ain't a value you can trust, you need to go trough all the
items in the cart, check up the price for each item and calculate the total. >>
Say a user with one of the many browser plugins that allows you to
modify post data, the user just adds all the items it wants and then
change the value for charge_total to 0, please calculate how pissed your >>boss will be.
$taxItem = new TaxItem();
$taxItem->amount = (($_POST['charge_total']/1.05) * 0.05);
$taxItem->description = "GST";
$taxItem->rate = "5.00";
$cartitem->tax = $taxItem;
$cart= (array) $cartitem ;
$cartarray = array( "cart" => $cartitem);
}
if (isset($_POST["submit"])){
$contact=new Contact;
$contact1= (array) $contact ;
$contact_details=array ( "contact_details" => $contact1 );
}
if (isset($_POST["submit"])){
$shipping = new Shipping;
$shipping1 = (array) $shipping;
$shipping_details=array( "shipping_details" => $shipping1 );
}
if (isset($_POST["submit"])){
$billing = new Billing;
$billing_details=array( "billing_details" => $billing1 );
}
$_SESSION['arr'] = serialize($arr);
$_SESSION['serialized_Obj'] = serialize($myObj);
<body>
<form action="https://www.nk.ca/pdsolutions/step5b.php" method="post" > >>>
<h2> Please review your order!</h2>
<?php
echo "<br /><br />";
why do you echo the html code? leave those outside the php code, you can >>have multiple <?php ?> in a page.
echo "<h3> Contact Information </h3>";
echo "<br /> My name is " . $contact->first_name . " " . >>$contact->last_name . "<br />";
echo "My E-mail address is " . $contact->email . " <br />";
echo "You can call me at " . $contact->phone . " <br /> <br />";
echo "<h3> Billing Information </h3>";
echo "<br /> Address :" . $billing->address_1 . "<br />";
echo $billing->address_2 . "<br />";
echo "Municipality:" . $billing->city . "<br />";
echo "Province:" . $billing->province . "<br />";
echo "Postal Code:" . $billing->postal_code . "<br /><br />";
echo "<h3> Shipping Information </h3>";
echo "<br /> Address :" . $shipping->address_1 . "<br />";
echo $shipping->address_2 . "<br />";
echo "Municipality:" . $shipping->city . "<br />";
echo "Province:" . $shipping->province . "<br />";
echo "Postal Code:" . $shipping->postal_code . "<br /><br />";
echo "<h3> Course Information </h3>";
Here you use a foreach loop that goes over the cart items, of course you >>need to deserialize the $_SESSION['serialized_Obj']. >>https://www.php.net/manual/en/control-structures.foreach.php
Got you on all accounts!
Form" id="reset" /><input type="submit" value="Place Your Order" name="submit" id="submit" >
<input onclick="history.back()" type="reset" value="Clear the
</form>
</body>
</html>
--
//Aho
--
Member - Liberal International This is doctor@nk.ca Ici doctor@nk.ca
Yahweh, King & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b >She didn't want to be evil, but by denying her nature she adopted it. >-unknown Beware https://mindspring.com
In article <u1cjle$k24$48@gallifrey.nk.ca>,
The Doctor <doctor@doctor.nl2k.ab.ca> wrote:
In article <k9th4vFauniU1@mid.individual.net>,
J.O. Aho <user@example.net> wrote:
On 4/14/23 03:12, The Doctor wrote:
95% there.maximum-scale=1.0, user-scalable=no">
Now I have split the form successfully I need to get
the cartitem in a printable format.
So given when I have worked on
<?=session_start();
error_reporting(E_ALL);
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1,
<link rel="stylesheet" type="text/css" href="css/css.css"/>
<link rel="stylesheet" type="text/css" href="css/css2.css"/>
</head>
<?php
if(!empty($_SESSION['sessiondata'])){
}
<?php
$myObj = [];
$storevalues= array();
$cartarray= array();
$cart= array();
$contact1=array();
$contact_details=array();
$shipping1=array();
$shipping_details=array();
$billing1=array();
$billing_details=array();
$arr2 =array();
Try to avoid all these arrays, they don't make life easier.
class Storevs{
}
class Item
{
}
class TaxItem
{
}
class CartItem
{
public $items;
public $subtotal;
public $tax;
};
class Contact
{
}
class Shipping
{
}
class Billing
{
}
Don't define the classes here, then you need to do it each file you use, >>> you create an php script that just includes the classes and then use include
https://www.php.net/manual/en/function.include.php
$items_count = 0;
$newsubtotal = 0;
$subtotal = 0;
$arr = array();
if (isset($_POST["submit"])){
$storevalues=(array) $storev;
}
if (isset($_POST["submit"])){
$cartitem= new CartItem();
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
if(isset($_POST['with_gst'][$key])){
$unit_cost = 63.00;
}else{
$unit_cost = 60.00; //no gst included
}
prices shouldn't be hard coded, you don't want to change the code just
for the price went up due of inflation, you change the price in a
database of some sort.
$item = new Item();
$item->url = "https://image";
$item->description = $_POST['description'][$key];
$item->product_code = $_POST['id'][$key];
$item->unit_cost = $unit_cost;
$item->quantity = $value;
$cartitem->items[] = $item;
}
}
$cartitem->subtotal = ($_POST['charge_total']/1.05);
Hey, this ain't a value you can trust, you need to go trough all the
items in the cart, check up the price for each item and calculate the total.
Say a user with one of the many browser plugins that allows you to
modify post data, the user just adds all the items it wants and then
change the value for charge_total to 0, please calculate how pissed your >>> boss will be.
$taxItem = new TaxItem();
$taxItem->amount = (($_POST['charge_total']/1.05) * 0.05);
$taxItem->description = "GST";
$taxItem->rate = "5.00";
$cartitem->tax = $taxItem;
$cart= (array) $cartitem ;
$cartarray = array( "cart" => $cartitem);
}
if (isset($_POST["submit"])){
$contact=new Contact;
$contact1= (array) $contact ;
$contact_details=array ( "contact_details" => $contact1 );
}
if (isset($_POST["submit"])){
$shipping = new Shipping;
$shipping1 = (array) $shipping;
$shipping_details=array( "shipping_details" => $shipping1 );
}
if (isset($_POST["submit"])){
$billing = new Billing;
$billing_details=array( "billing_details" => $billing1 );
}
$_SESSION['arr'] = serialize($arr);
$_SESSION['serialized_Obj'] = serialize($myObj);
<body>
<form action="https://www.nk.ca/pdsolutions/step5b.php" method="post" > >>>>
<h2> Please review your order!</h2>
<?php
echo "<br /><br />";
why do you echo the html code? leave those outside the php code, you can >>> have multiple <?php ?> in a page.
echo "<h3> Contact Information </h3>";$contact->last_name . "<br />";
echo "<br /> My name is " . $contact->first_name . " " .
echo "My E-mail address is " . $contact->email . " <br />";
echo "You can call me at " . $contact->phone . " <br /> <br />";
echo "<h3> Billing Information </h3>";
echo "<br /> Address :" . $billing->address_1 . "<br />";
echo $billing->address_2 . "<br />";
echo "Municipality:" . $billing->city . "<br />";
echo "Province:" . $billing->province . "<br />";
echo "Postal Code:" . $billing->postal_code . "<br /><br />";
echo "<h3> Shipping Information </h3>";
echo "<br /> Address :" . $shipping->address_1 . "<br />";
echo $shipping->address_2 . "<br />";
echo "Municipality:" . $shipping->city . "<br />";
echo "Province:" . $shipping->province . "<br />";
echo "Postal Code:" . $shipping->postal_code . "<br /><br />";
echo "<h3> Course Information </h3>";
Here you use a foreach loop that goes over the cart items, of course you >>> need to deserialize the $_SESSION['serialized_Obj'].
https://www.php.net/manual/en/control-structures.foreach.php
Got you on all accounts!
Form" id="reset" /><input type="submit" value="Place Your Order" name="submit" id="submit" >
<input onclick="history.back()" type="reset" value="Clear the
</form>
</body>
</html>
--
//Aho
All right, trying to debug this here is what is happening:
code snippet
echo "<h3> Course Information </h3>";
echo '<pre>'; print_r($cart); echo '</pre>';
$keys = array_keys($cart);
print_r($keys);
foreach ($_POST['quantity'] as $key => $value) {
if( $value > 0){
echo "quantity " . $item->quantity . " of " . $item->description
. " <br />";}
}
?>
REsult:For me it seems you have something wrong with your calculation (60*1 +
COURSE INFORMATION
Array
(
[items] => Array
(
[0] => Item Object
(
[url] => https://www.pdsolutions.ca/images/newwhiteheader.png
[description] => Alberta Legislation Update
[product_code] => ALU-1304
[unit_cost] => 60
[quantity] => 1
)
[1] => Item Object
(
[url] => https://www.pdsolutions.ca/images/newwhiteheader.png
[description] => AA training and exam
[product_code] => AAtt-1306
[unit_cost] => 60
[quantity] => 1
)
)
[subtotal] => 320
[tax] => TaxItem Object
(
[amount] => 16
[description] => GST
[rate] => 5.00
)
)
Array ( [0] => items [1] => subtotal [2] => tax ) quantity 1 of AA training and exam quantity 1 of AA training and exam
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (2 / 14) |
Uptime: | 119:11:29 |
Calls: | 7,612 |
Files: | 12,787 |
Messages: | 5,684,030 |