This topic is locked
[SOLVED]

 Assign XML obtained data as default value

5/2/2018 4:45:08 PM
PHPRunner General questions
U
ustunsoz author

I am getting a USD currency exchange rate from official provided XML and need to use as default value. On this purpose, trying to create a session variable in the Add page:before process event as follow:


$veri=simplexml_load_file("http://www.tcmb.gov.tr/kurlar/today.xml";);

$_SESSION["UsdTrl"]=$data[$veri->Currency[0]->BanknoteBuying];


All syntax seems ok and page not giving error at all, but the currency does not come in to Session variable.
Where is my mistake???

Admin 5/2/2018

You need to check what value $veri->Currency[0]->BanknoteBuying holds. Try to print it on the page instead of assigning to session variable.

U
ustunsoz author 5/3/2018

I have checked and it is working well, I have seen the currency showing as in XML

Admin 5/3/2018

How exactly you checking this?
What you see with your eyes in XML file and what value $veri->Currency[0]->BanknoteBuying variable has in PHP code are two different things.

U
ustunsoz author 5/6/2018

Well, I have tried to print as follow on List Page:Before process event with following code



$veri=simplexml_load_file("http://www.tcmb.gov.tr/kurlar/today.xml";);

$dolartl=$veri->Currency[0]->BanknoteBuying;

$_SESSION["UsdTrl"]=$data[$dolartl];

echo $dolartl;

echo $_SESSION["UsdTrl"];


In the above code echo $dolartl; is showing the currency value as it is but echo $_SESSION["UsdTrl"]; part displays nothing.
However, if I use same code onAdd Page: Before Process event the web page giving complete error and not opening

Admin 5/6/2018

$data[$dolartl] is completely meaningless here. Where this $data is coming from?

U
ustunsoz author 5/7/2018

It is what I have found from topics as "how to assign value to session variable"
I will appreciate if you just lead me with a correct code, instead of criticizing my mistakes. I am learning and sorry to bother you

U
ustunsoz author 5/7/2018

Now Okey, with following code I can see the values on the page

$veri=simplexml_load_file("http://www.tcmb.gov.tr/kurlar/today.xml";);

$dolartl=$veri->Currency[0]->BanknoteBuying;

$_SESSION["UsdTrl"]=$dolartl;

echo $dolartl;

echo $_SESSION["UsdTrl"];


The only thing can you tell me why it is working on the List page Before Process event, but not working on Add Page: Before Display event? when I add the code on add page, the page is not opening at all!!
The Error message comes with very long list and at the end of page: Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in [no active file]:0 Stack trace: #0 {main} thrown in [no active file] on line 0

U
ustunsoz author 5/7/2018

Now All is working well with following code, thanks for your time and effort...

$veri=simplexml_load_file("http://www.tcmb.gov.tr/kurlar/today.xml";);

$dolartl=(string)$veri->Currency[0]->BanknoteBuying;

$_SESSION["UsdTrl"]=$dolartl;