A
A
Alexander Interesting2020-05-09 14:22:51
PHP
Alexander Interesting, 2020-05-09 14:22:51

Why does asXML() sometimes not work in simplexml?

Simplexml_load_file('some.xml')->asXML(); works weird for me.
In some cases, everything works perfectly, and in some it displays an error 500.
That is, everything works in this code:

<?php
  $login = $_POST['user'];
  $xml = simplexml_load_file('online.xml');
  $xml->$login->lastactiv=date("YmdHi");
  $xml->$login->nlastactiv=date("Y.m.d H:i");
    file_put_contents('online.xml', $xml->asXML());
?>

And this is the 500 error:
<?php
  $title = $_POST['title'];
  $email = $_POST['email'];
  $name = $_POST['name'];
  $tz = $_POST['timezone'];
  $a = $_POST['about'];
  $sms = $_POST['sendSMS'];
  $st = $_POST['sendsTo'];

  $xml = simplexml_load_file('some.xml');
  $xml->$login->TimeZone=$tz;
  $xml->$login->about=$a;
    $xml->$login->sendSMS=$sms;
    $xml->$login->sendsTo=$st;
    file_put_contents('some.xml', $xml->asXML());
?>

And I'm sure that the error is in $ xml- >asXML(), because when I don't use it, everything is fine, but when I write echo $xml->asXML();, that's it, error 500

validations found no errors.
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question