Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #19435
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Replace punctuation in an associative array |
| Date | 2023-04-14 19:34 +0200 |
| Message-ID | <k9th4vFauniU1@mid.individual.net> (permalink) |
| References | <ttq5np$i9r$50@gallifrey.nk.ca> <u18q9f$qtb$29@gallifrey.nk.ca> <k9qanbFqbf1U1@mid.individual.net> <u1a06u$t8d$29@gallifrey.nk.ca> <u1a99j$1gfe$15@gallifrey.nk.ca> |
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
> ?>
> <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>
--
//Aho
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar
Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-02 12:44 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-02 14:23 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-03 01:03 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-03 10:36 +0100
Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <techfan55555@hotmail.com> - 2023-03-08 09:22 -0800
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:24 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-03 08:14 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 05:19 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 11:07 +0100
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-04 14:42 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 14:57 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-04 16:38 +0100
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 00:41 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-04 23:58 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 01:39 +0100
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-03-05 00:52 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-05 12:16 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-05 14:08 +0000
Re: Bureaucracy (Was: Replace punctuation in an associative array) "J.O. Aho" <user@example.net> - 2023-03-06 09:30 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 16:43 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-03-07 18:56 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-07 22:53 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-08 23:44 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-09 01:25 +0000
Re: Replace punctuation in an associative array Arno Welzel <usenet@arnowelzel.de> - 2023-03-10 09:08 +0100
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-10 15:20 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-01 14:08 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-06 00:26 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-12 22:45 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 07:41 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 11:50 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-13 14:26 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-13 22:37 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 01:12 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-14 19:34 +0200
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-14 22:21 +0000
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-16 12:40 +0000
Re: Replace punctuation in an associative array "J.O. Aho" <user@example.net> - 2023-04-16 22:03 +0200
Re: Replace punctuation in an associative array Ezimene nimi Teine nimi <yyyyyeeeee00000@writeme.com> - 2023-03-06 03:23 -0800
Re: Replace punctuation in an associative array The Doctor <doctor@doctor.nl2k.ab.ca> - 2023-03-06 16:21 +0000
Re: Replace punctuation in an associative array V <vvvvvvvvvvvvvvvvvvvv11111@mail.ee> - 2023-04-03 06:55 -0700
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-03 14:18 +0000
Re: Replace punctuation in an associative array Angel <heyeeeeeeeeeeeeeeeeeee@gmail.com> - 2023-04-15 05:33 -0700
Re: Replace punctuation in an associative array doctor@doctor.nl2k.ab.ca (The Doctor) - 2023-04-15 13:52 +0000
csiph-web