Re: JSON and PHP
ThE sUn <[email protected]>
| Newsgroups | comp.lang.php |
|---|---|
| Message-ID | <[email protected]> |
Have a nice day, Doctor......
🌞
On Wednesday, December 28, 2022 at 2:35:00 AM UTC+2, The Doctor wrote:
> Trying to implement a JSON array in PHP
>
>
> Using
>
>
> <?=session_start();
> error_reporting(E_ALL);
> ?>
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <meta name="robots" content="index, follow" />
> <link rel="stylesheet" type="text/css" href="css/css.css"/>
> <link rel="stylesheet" type="text/css" href="css/css2.css"/>
> <link rel="stylesheet" href="css/uniform.default.css" type="text/css" media="screen">
> <link rel="stylesheet" href="css/uniform.agent.css" type="text/css" media="screen">
> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
> </head>
> <body>
> <?php
> if(!empty($_SESSION['sessiondata'])){
> }
> ?>
> <div id="wrapper">
> <!--header begins-->
> <?php
> include("includes/header.php");
> ?>
> <!--header ends-->
> <FORM ACTION="https://gatewayt.moneris.com/chkt/request/request.php" method=post>
> <div id="outerDiv" style="width:400px"; height"300px">`
> <div id="monerisCheckout"></div></div>
> <script src="https://gatewayt.moneris.com/chkt/js/chkt_v1.00.js"></script>
> <script>
> var myCheckout = new monerisCheckout();
> myCheckout.setMode("qa");
> myCheckout.setCheckoutDiv("monerisCheckout");
> myCheckout.setCheckout([ticket #]);
> myCheckout.setCallback("page_loaded", myPageLoad);
> myCheckout.setCallback("cancel_transaction", myCancelTransaction);
> myCheckout.setCallback("error_event", myErrorEvent);
> myCheckout.setCallback("payment_receipt", myPaymentReceipt);
> myCheckout.setCallback("payment_complete", myPaymentComplete);
> </script>
> <?php
>
> ?>
> <center>
> <!-- Store Settings-->
> <INPUT TYPE="HIDDEN" NAME="ps_store_id" VALUE="<?=$myObj->store_id?>">
> <INPUT TYPE="HIDDEN" NAME="checkout_id" VALUE="<?=$myObj->checkout_id?>">
> <!------- DEFINE CHARGE TOTAL HERE --->
> <br/><br/><h3>Your Purchase Total Is: </h3> <br/> <h2>$<?=$myObj->txn_total?></h2>
> <INPUT TYPE="hidden" NAME="charge_total" VALUE="<?=$myObj->txn_total?>"><br><br>
> <!-- Unique Order ID -->
> <!--INPUT TYPE="hidden" NAME="order_id" VALUE="<?=$myObj->sessValue?>"-->
> <!-- Additional Optional Details -->
> <input type="hidden" name="cust_id" value="<?=$MyObj->sessValue?>">
> <input type="hidden" name="email" value="<?=$myObj->email?>">
> <input type="hidden" name="note" value="">
> <!-- Item Information -->
> <?php
>
> $items_count = 1;
> $subtotal = 0;
> $arr = array();
> 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
> }
>
> $subtotal = ($unit_cost * $value);
> $quantity = ($value);
>
>
> ?>
> <input name="quantity<?=$items_count?>" value="<?=$quantity?>">
> <input name="description<?=$items_count?>" value="<?=$_POST['description'][$key]?>">
> <input name="id<?=$items_count?>" value="<?=$_POST['id'][$key]?>">
> <input name="price<?=$items_count?>" value="<?=$unit_cost?>">
> <input name="subtotal<?=$items_count?>" value="<?=$subtotal?>">
> <?php
> $myObj = [];
> if (isset($_POST["submit"])){
> (array_push($myObj,[
> 'sessValue' =>[ $_POST['sessionid1']],
> 'username'=> ["demouser"],
> 'password' => ["password"],
> 'store_id' => ["store3"],
> 'checkout_id' => ["chkt23NGFtore3"],
> 'api_token' => ["yesguy"],
> 'txn_total' => [$_POST['charge_total']],
>
> 'bill_first_name' =>[$_POST['bill_first_name']],
> 'bill_last_name' => [$_POST['bill_last_name']],
> 'bill_company_name' => [$_POST['bill_company_name']],
> 'bill_address_one' => [$_POST['bill_address_one']],
> 'bill_city' => [$_POST['bill_city']],
> 'bill_state_or_province' => [$_POST['bill_state_or_province']],
> 'bill_postal_code' => [$_POST['bill_postal_code']],
> 'bill_phone' => [$_POST['bill_phone']],
> 'email' => [$_POST['email']],
> $MyObj[] = array(
> "cart"=>array(
> "items"=>array(
> 'url' => ['https:\/\/www.pdsolutions.ca\/images\/newwhiteheader.png'],
> 'description' => [$_POST['description'][$key]],
> 'unit_cost' => $unit_cost,
> 'quantity' => $value,
> ),
> 'subtotal' => $subtotal,
> ),
> ),
> array_push($arr, $MyObj),
> ]));
>
> $items_count++;
> }
>
> }
> ?>
> <!-- Billing Information -->
> <input type="hidden" name="bill_first_name" value="<?=$MyObj->bill_first_name?>">
> <input type="hidden" name="bill_last_name" value="<?=$bill_last_name?>">
> <input type="hidden" name="bill_company_name" value="<?=$bill_company_name?>">
> <input type="hidden" name="bill_address_one" value="<?=$bill_address_one?>">
> <input type="hidden" name="bill_city" value="<?=$bill_city?>">
> <input type="hidden" name="bill_state_or_province" value="<?=$bill_state_or_province?>">
> <input type="hidden" name="bill_postal_code" value="<?=$bill_postal_code?>">
> <input type="hidden" name="bill_country" value="<?=$bill_country?>">
> <input type="hidden" name="bill_phone" value="<?=$bill_phone?>">
> <input type="hidden" name="bill_fax" value="<?=$bill_fax?>">
>
> <?php
> $myJSON = json_encode($myObj);
>
> echo $myJSON;
> }
> ?>
> <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Click to proceed to Secure Page">
> </center>
> </FORM>
>
> <?php
> include("includes/footer.php");
> ?>
> </div>
> </body>
> </html>
>
> I am getting an output of
>
> YOUR PURCHASE TOTAL IS:
>
> $
>
>
> null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null
> 1
>
> Fatigue Management
>
> FM-1301
>
> 60
>
> 60
> [{"sessValue":[null],"username":["demouser"],"password":["password"],"store_id":["store3"],"checkout_id":["chkt23NGFtore3"],"api_token":["yesguy"],"txn_total":["126.00"],"bill_first_name":["Dave"],"bill_last_name":["Yadallee"],"bill_company_name":[""],"bill_address_one":[""],"bill_city":[""],"bill_state_or_province":[""],"bill_postal_code":[""],"bill_phone":["7804734587"],"email":["[email protected]"],"0":{"cart":{"items":{"url":["https:\\\/\\\/www.pdsolutions.ca\\\/images\\\/newwhiteheader.png"],"description":["Fatigue Management"],"unit_cost":60,"quantity":"1"},"subtotal":60}},"1":1}]
> 1
>
> Pesticide Applicator Records
>
> PAR-1302
>
> 60
>
> 60
> [{"sessValue":[null],"username":["demouser"],"password":["password"],"store_id":["store3"],"checkout_id":["chkt23NGFtore3"],"api_token":["yesguy"],"txn_total":["126.00"],"bill_first_name":["Dave"],"bill_last_name":["Yadallee"],"bill_company_name":[""],"bill_address_one":[""],"bill_city":[""],"bill_state_or_province":[""],"bill_postal_code":[""],"bill_phone":["7804734587"],"email":["[email protected]"],"0":{"cart":{"items":{"url":["https:\\\/\\\/www.pdsolutions.ca\\\/images\\\/newwhiteheader.png"],"description":["Pesticide Applicator Records"],"unit_cost":60,"quantity":"1"},"subtotal":60}},"1":2}] [{"sessValue":[null],"username":["demouser"],"password":["password"],"store_id":["store3"],"checkout_id":["chkt23NGFtore3"],"api_token":["yesguy"],"txn_total":["126.00"],"bill_first_name":["Dave"],"bill_last_name":["Yadallee"],"bill_company_name":[""],"bill_address_one":[""],"bill_city":[""],"bill_state_or_province":[""],"bill_postal_code":[""],"bill_phone":["7804734587"],"email":["[email protected]"],"0":{"cart":{"items":{"url":["https:\\\/\\\/www.pdsolutions.ca\\\/images\\\/newwhiteheader.png"],"description":["Pesticide Applicator Records"],"unit_cost":60,"quantity":"1"},"subtotal":60}},"1":2}] [{"sessValue":[null],"username":["demouser"],"password":["password"],"store_id":["store3"],"checkout_id":["chkt23NGFtore3"],"api_token":["yesguy"],"txn_total":["126.00"],"bill_first_name":["Dave"],"bill_last_name":["Yadallee"],"bill_company_name":[""],"bill_address_one":[""],"bill_city":[""],"bill_state_or_province":[""],"bill_postal_code":[""],"bill_phone":["7804734587"],"email":["[email protected]"],"0":{"cart":{"items":{"url":["https:\\\/\\\/www.pdsolutions.ca\\\/images\\\/newwhiteheader.png"],"description":["Pesticide Applicator Records"],"unit_cost":60,"quantity":"1"},"subtotal":60}},"1":2}]
>
>
> Just wonder how to supress repeats.
> --
> Member - Liberal International This is [email protected] Ici [email protected]
> 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
> Happy Christmas 2022 and Merry New Year 2023 Beware https://mindspring.com