Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Put variable into array without quotes

So i am stuck with one problem i have $amount wich is $_post["amount"] however the rpc requires that numeric values has to be inserted without quotes so when i type the amount manually in the php pages it works and generates this request:

"{"method":"sendTransaction","params":{"anonymity":0,"fee":1000000,"addresses":["S6EHUg5k8K2br3mAVnd13AGGjYqXw1rCzjGn6z7Wnf7eaAE8nZtwZD1dcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jW52w1q"],"transfers":[{"amount":70000,"address":"S6F8bN49qSUK2SunXpB8rnEp6LdCXoS2f6ZSfC8pxmhYjhqqkNj6o4jdcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jVCmZDm"}]}}"

But when i use the value from the form it generates this request

"{"method":"sendTransaction","params":{"anonymity":0,"fee":1000000,"addresses":["S6EHUg5k8K2br3mAVnd13AGGjYqXw1rCzjGn6z7Wnf7eaAE8nZtwZD1dcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jW52w1q"],"transfers":[{"amount":"70000","address":"S6F8bN49qSUK2SunXpB8rnEp6LdCXoS2f6ZSfC8pxmhYjhqqkNj6o4jdcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jVCmZDm"}]}}"

here is the code:
PHP Code

<?php 
$da 
= array("method" => "sendTransaction", "params" => array("anonymity" => 0 ,"fee" => 1000000, "addresses" => array($address1), "transfers" => array(array("amount" => $amount  ,"address" => $receive)))); 
=============================================
Nothing yet
=============================================
(Jan 30, 2018 03:15 AM)deadsh0t Wrote:  So i am stuck with one problem i have $amount wich is $_post["amount"] however the rpc requires that numeric values has to be inserted without quotes so when i type the amount manually in the php pages it works and generates this request:

"{"method":"sendTransaction","params":{"anonymity":0,"fee":1000000,"addresses":["S6EHUg5k8K2br3mAVnd13AGGjYqXw1rCzjGn6z7Wnf7eaAE8nZtwZD1dcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jW52w1q"],"transfers":[{"amount":70000,"address":"S6F8bN49qSUK2SunXpB8rnEp6LdCXoS2f6ZSfC8pxmhYjhqqkNj6o4jdcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jVCmZDm"}]}}"

But when i use the value from the form it generates this request

"{"method":"sendTransaction","params":{"anonymity":0,"fee":1000000,"addresses":["S6EHUg5k8K2br3mAVnd13AGGjYqXw1rCzjGn6z7Wnf7eaAE8nZtwZD1dcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jW52w1q"],"transfers":[{"amount":"70000","address":"S6F8bN49qSUK2SunXpB8rnEp6LdCXoS2f6ZSfC8pxmhYjhqqkNj6o4jdcc2L3h137P1NTKxh9HM6y5AfBHtwnGjp21jVCmZDm"}]}}"

here is the code:
PHP Code

<?php 
$da 
= array("method" => "sendTransaction", "params" => array("anonymity" => 0 ,"fee" => 1000000, "addresses" => array($address1), "transfers" => array(array("amount" => $amount  ,"address" => $receive)))); 

I am not sure if this will work, but you can try using function stripslashes()

PHP Code

<?php 
$da 
= array("method" => "sendTransaction", "params" => array("anonymity" => 0 ,"fee" => 1000000, "addresses" => array($address1), "transfers" => array(array("amount" => stripslashes($amount), "address" => $receive)))); 
(Jan 30, 2018 06:57 AM)Devsoft™ Wrote:  I am not sure if this will work, but you can try using function stripslashes()

PHP Code

<?php 
$da 
= array("method" => "sendTransaction", "params" => array("anonymity" => 0 ,"fee" => 1000000, "addresses" => array($address1), "transfers" => array(array("amount" => stripslashes($amount), "address" => $receive)))); 

thanks however it doesnt seem to work , but i just fixed it by adding JSON_NUMERIC_CHECK to de encoding part
=============================================
Nothing yet
=============================================
Have you tried using this, real_escape_string.
[Image: signaturetwo.png]
PHP Code

<?php 
$s 
= "abcdefg";
$n1 = "100.99";
$n2 = 100.325;

$x = array("S" => $s, "n1" => $n1, "n2" => $n2);

echo 
json_encode($x);

echo 
"<br>";

$x = array("S" => $s, "n1" => (float) $n1, "n2" => $n2);
echo 
json_encode($x); 

returns
{"S":"abcdefg","n1":"100.99","n2":100.325}

{"S":"abcdefg","n1":100.99,"n2":100.325}


You need to type cast/juggle -> http://php.net/manual/en/language.types....ggling.php
Try using intval, seems like $amount is a string.

Replace $amount with intval($amount).
(Jan 30, 2018 09:39 AM)Charger Wrote:  
PHP Code

<?php 
$s 
= "abcdefg";
$n1 = "100.99";
$n2 = 100.325;

$x = array("S" => $s, "n1" => $n1, "n2" => $n2);

echo 
json_encode($x);

echo 
"<br>";

$x = array("S" => $s, "n1" => (float) $n1, "n2" => $n2);
echo 
json_encode($x); 

returns
{"S":"abcdefg","n1":"100.99","n2":100.325}

{"S":"abcdefg","n1":100.99,"n2":100.325}


You need to type cast/juggle -> http://php.net/manual/en/language.types....ggling.php

yes this works also i will keep this in mind thanks for now im using JSON_NUMERIC_CHECK
=============================================
Nothing yet
=============================================
(Jan 31, 2018 02:43 AM)deadsh0t Wrote:  yes this works also i will keep this in mind thanks for now im using JSON_NUMERIC_CHECK

Glad that fixed it. Just keep in mind that JSON_NUMERIC_CHECK is kind of a half-assed constant in PHP.
http://www.garageenbois.fr/posts/why-jso...-good-idea


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by Sir-TeabagNov 19, 2017 08:03 PM 5 208 Nov 19, 2017 08:03 PM
Last Post: Charger
[PHP] by A1ema1akraJul 1, 2017 04:24 PM 8 410 Jul 1, 2017 04:24 PM
Last Post: +Haze
[PHP] by DJSanderrrMar 2, 2016 06:20 PM 21 358 Mar 2, 2016 06:20 PM
Last Post: Terebic