title: PHP Call to a member function saveXML() on a non-object on AJAX POST?
body: <p>Can anyone see what's wrong with my code? The error I'm getting is as follows:</p>
  
  <p>Fatal error: Call to a member function saveXML() on a non-object in /path/to/php/file.php on line 35</p>
  
  <p>Basically I'm just trying to update an XML nodeValue which changes the UI depending on the value set in the "AVAILABILITY" tag.</p>
  
  <p>==================== UPDATE ====================</p>
  
  <p>The XML file is now not being overwritten with the new value for the ('STATUS') node inside ('AVAILABILITY') tag, is there something I'm doing wrong?!</p>
  
  <p>================================================</p>
  
  <p>XML Structure</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;WORK&gt;
      &lt;AVAILABILITY&gt;
          &lt;STATUS&gt;0&lt;/STATUS&gt; // Not being changed?!
      &lt;/AVAILABILITY&gt;
      &lt;SLIDE&gt;
          &lt;ID&gt;YY001&lt;/ID&gt;
          &lt;TITLE&gt;YourEdentity&lt;/TITLE&gt;
          &lt;LINK&gt;http://youredentity.campearce.co.uk&lt;/LINK&gt;
          &lt;THUMB&gt;your_ed.png&lt;/THUMB&gt;
          &lt;CAPTION&gt;This is YourEdentity&lt;/CAPTION&gt;
      &lt;/SLIDE&gt;
  &lt;/WORK&gt;
  </code></pre>
  
  <p>PHP Script:</p>
  
  <pre><code>&lt;?php
  
  $url = "../content/slides.xml";
  $xml = simplexml_load_file($url);
  
  if(!file_exists($url))
  {
  echo "Unable to locate file";
  }
  else
  {
  $root = $xml-&gt;WORK;
  $slides = $root-&gt;SLIDE;
  
  if(isset($_POST['action']) &amp;&amp; !empty($_POST['action']))
  {
      $action = $_POST['action'];
      switch($action)
      {
          case 'deleteslide' : delete_slide(); break;
          case 'createslide' : create_slide(); break;
          case 'changeavail' : change_avail($root, $_POST['status'], $xml, $url); break;
      }   
  }
  }
  
  function change_avail($root_node, $status, $xml, $location){
  
  $availability_node = $root_node-&gt;AVAILABILITY;
  $status_node[0] = $availability_node-&gt;STATUS;
  parse_str($status, $statustr);
  $status_node[0] = $statustr;
  
  file_put_contents($location, $xml-&gt;asXML());
  
  echo $xml-&gt;asXML();
  }
  
  function save_toxml($xml, $location)
  {
  $fp = fopen($location, 'w');
  fwrite($fp, $xml-&gt;asXML());
  fclose($fp);
  echo $xml-&gt;asXML();
  }
  
  ?&gt;
  </code></pre>