I need some PHP and XML help

I am trying to create a site. The basic function for the site is to link to a few different aspects of a company and then to create a list in xml of e-mails if people choose to sign up for the newsletter. I have been at it for a few hours now and feel very lost. Any help, tips or information on what I am doing wrong would be appreciated.

[php]<?php
// define configuration file name and path
$configFile = ‘config.xml’;

// if form not yet submitted
// display form
if (!isset($_POST['submit'])) {
  
  // set up array with default parameters
  $data = array();
  $data['email'] = null;
    // read current configuration values
  // use them to pre-fill the form
  if (file_exists($configFile)) {
    $doc = new DOMDocument();
    $doc->preserveWhiteSpace = false;
    $doc->load($configFile);
    $people = $doc->getElementsByTagName('people');
    foreach ($people->item(0)->childNodes as $node) {
      $data[$node->nodeName] = $node->nodeValue;  
    }        
  }

?>

<?php // if form submitted // process form input } else { // read submitted data $config = $_POST['data'];
  // generate new XML document
  $doc = new DOMDocument();
  
  // create and attach root element <configuration> 
  $root = $doc->createElement('configuration');
  $configuration = $doc->appendChild($root);
  
  // create and attach <people> element under <configuration>
  $people = $doc->createElement('people');
  $configuration->appendChild($people);
  
  // write each configuration value to the file
  foreach ($config as $key => $value) {
    if ($value) {
      $elem = $doc->createElement($key);
      $text = $doc->createTextNode($value);
      $people->appendChild($elem);
      $elem->appendChild($text);          
    }
  }
  
  // format XML output
  // save XML file
  $doc->formatOutput = true;
  $doc->save($configFile) or die('ERROR: Cannot write configuration file');      
  echo 'Configuration data successfully written to file. Below is what has been entered.';
  echo '$data['email']';
}    

?>
[/php]

This is the code for the second php page

[php]<?php
// retrieve details from POST submission
$name = $_POST[‘email’];
// generate new XML document
$doc = new DOMDocument();
// create and attach root element
$root = $doc->createElement(‘configuration’);
$configuration = $doc->appendChild($root);
// create and attach element under
$people = $doc->createElement(‘people’);
$configuration->appendChild($people);
// write each configuration value to the file
foreach ($config as $key => $value) {
if ($value) {
$elem = $doc->createElement($key);
$text = $doc->createTextNode($value);
$people->appendChild($elem);
$elem->appendChild($text);
}
}
// format XML output
// save XML file
$doc->formatOutput = true;
$doc->save($configFile) or die(‘ERROR: Cannot write configuration file’);
$config = simplexml_load_file(‘config.xml’);
$config = new SimpleXMLElement(‘config.xml’, null, true);
?>
[/php]

Well, first, why would you want to use XML for this. A database would be of better use.

But, doing it your way, you have an input type in your form that is set to “email”. There is no such thing.
Next, you try to use an input of type “image”. This is used to display an image and use it as a SUBMIT button
only. So, you do not have any useful inputs in your form. You would normally have some sort of email form if you want to save emails.

Also, you mentioned saving a XML list of emails. Do you mean you want a list of the actual emails or just links pointing to them? I think we need more info about what you are attempting to accomplish in this project.

Sponsor our Newsletter | Privacy Policy | Terms of Service