0

I'm from a design background and only really have experience with HTML and CSS so I'm very new to anything involving PHP and can only grasp chopping and changing bits of code at best of times.

I have found some PHP code that allows me to create a web form that when used, includes the users name, email, email subject and email body - this has been tested and works just fine and I'm receiving emails from the form with no problems.

What I want to do now is have the form create/update an XML file that I have hosted with the users info every time someone uses the form.

I tried searching and couldn't really find anything that worked.

My PHP:

<?php

$ip = $_POST['ip']; 
$httpref = $_POST['httpref']; 
$httpagent = $_POST['httpagent']; 
$visitor = $_POST['visitor']; 
$visitormail = $_POST['visitormail']; 
$notes = $_POST['notes'];
$attn = $_POST['attn'];

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) 
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n"; 
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! "); 
}

$todayis = date("l, F j, Y, g:i a");

$attn = $attn ; 
$subject = $attn; 

$notes = stripcslashes($notes); 

$message = "
Subject: $attn \n
Message: $notes \n 
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
";

$from = "From: $visitormail\r\n";


mail('youremail@website.com', $subject, $message, $from);

?>

I found this PHP and tried adjusting it to work with my code but it doesn't seem to work:

<?php 

$file="test_xml.xml";

$visitor="Name";
$ip="IP";

//load xml object
$xml= simplexml_load_file($file);

//assign name
$xml->auth->ids = $visitor;

//assign ip
$xml->auth->key = $ip;

//store the value into the file
file_put_contents($file, $xml->asXML());

?>

Am I on the right track at all?

SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
  • I would recommend [DOMDocument](http://stackoverflow.com/a/2038550/499581) — it's very easy to work with too. – l'L'l Aug 29 '14 at 08:54

1 Answers1

0

Just replace your XML code in your php with this one and try it out

$xml = new SimpleXMLElement('');

    $mydata = $xml->addChild('VisitorInfo');
    $mydata->addChild('Visitor',$Visitor);
    $mydata->addChild('Key',$ip);

    $mydata->PHP_EOL;

mysql_close($db);

$fp = fopen("VisitorData.xml","wb");


fwrite($fp,$xml->asXML());

fclose($fp);
Ethic Or Logics
  • 111
  • 1
  • 13
  • I've added it to the code in my php but it doesn't seem to do anything. My messages are sending fine and not erroring but it doesn't seem to save the date to an XML – SaturnsEye Aug 29 '14 at 09:06