masimies wrote:But with square brackets, there is no difference for the function in result. Without them, i have the correct result to input form allready. All the included rows are there.
How do you know all the included rows are there?
masimies wrote:Problem is the fwrite section. It does not write all rows to xml-file. Only one row in form.
So i need somekind of loop to it, write all productname-rows to xml-file.
Yes, you need a loop. You also really need to indent your PHP code or it is hard to read, e.g.,
if (isset($_POST['submit'])) {
$msg = "";
if (empty($_POST['offer'])) {
$msg = "Please enter a file name";
}
if (empty($msg)) {
$xmldoc = $_POST['offer'] . ".xml";
if (!file_exists($xmldoc)) {
if ($fp = fopen($xmldoc, 'w+')) {
fwrite($fp, "<?xml version='1.0' ?>\n");
fwrite($fp, '<'.$_POST['relement'].'>');
fwrite($fp, "\n");
fwrite($fp, "<content>\n");
fwrite($fp, '<ProductName>'.$ProductName."</ProductName>\n");
fwrite($fp, '<OrderedAmt>'.$OrderedAmt."</OrderedAmt>\n");
fwrite($fp, '<unit>'.$unit."</unit>\n");
fwrite($fp, '<RetailPrice>'.$RetailPrice."</RetailPrice>\n");
fwrite($fp, '<TaxRate>'.$TaxRate."</TaxRate>\n");
fwrite($fp, '<Discount>'.$Discount."</Discount>\n");
fwrite($fp, '<Tax>'.$Tax."</Tax>\n");
fwrite($fp, '<TaxFree>'.$TaxFree."</TaxFree>\n");
fwrite($fp, '<Total>'.$Total."</Total>\n");
fwrite($fp, '<FullCost>'.$FullCost."</FullCost>\n");
fwrite($fp, '<Profit>'.$Profit."</Profit>\n");
fwrite($fp, '<OrderStatus>'.$OrderStatus."</OrderStatus>\n");
fwrite($fp, "</content>\n");
fwrite($fp, "</".$_POST['relement'].">");
fclose($fp);
$msg = "The XML document called ".$xmldoc. " has been created";
} else {
$msg = "There was an error, could not create the XML document.";
}
} else {
$msg = "File name already exists, please try again";
}
}
}
Furthermore, you should be escaping the values that come from incoming variables like $_POST['relement'], e.g., by using [man]htmlspecialchars[/man].
Actually, you do not need so many fwrite calls. You could have constructed a string, then write that string with a single fwrite call.