I have just migrated an intranet server from Windows Server 2008 and IIS8 to Server 2016 and IIS10 — everything is good except for one little PHP function– the rest of the xml manipulation pages are all done in ASP and work just fine– I have checked and rechecked the PHP install and even tried cloning the php 5.6 folder from the old server (which also has the php config file) to no avail. No errors are generated in the PHP log file! I think I prefer to just rewrite the code in ASP, but I think it is much more complicated than the PHP code. Any help would be greatly appreciated, as my time is limited and I have lots of other tasks occupying me. Already spent way too much time on this one single function. The basic idea is to look at a particular cid (row) and just toggle the Status from In to Out or vice-versa. Have a feeling that ASP code may be the faster route than poking around with the PHP installation."
Hoping this is an easy question for the right person.
Calling the function like so:
function change(stat,row) {
$.ajax({
type: "POST",
url: "js/update.php",
data: {status: stat, statrow: row},
success: function() {
location.reload();
}
});
The php function:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$status = $_POST['status'];
$row = $_POST['statrow'];
$rownum = (int)$row;
// echo $status," ",$rownum;
// load the document
// the root node is <Crew_List/> so we load it into $crewlist
$crewlist = simplexml_load_file('../xml/crew-list.xml');
//$currstatus = $crewlist->item[$rownum]->Status;
// update
if ($status == "In") {
$crewlist->item[$rownum]->Status = "Out";
} else {
$crewlist->item[$rownum]->Status = "In";
}
// save the updated document
$crewlist->asXML('../xml/crew-list.xml');
// echo "done";
?>
</body>
</html>
XML file:
<?xml version="1.0" standalone="true"?>
-<Crew_List>
-<item>
<cid>1</cid>
<Status>Out</Status>
<Name>Crew1</Name>
<Title>Purser</Title>
<Phone_Number>-</Phone_Number>
<EMail/>
</item>
-<item>
<cid>2</cid>
<Status>In</Status>
<Name>Crew2</Name>
<Title>Captain</Title>
<Phone_Number>-</Phone_Number>
<EMail/>
</item>
</Crew_List>
Tried lots of stuff with PHP Manager and could not get php function to work. Works fine on the other server with IIS8 and PHP 5.6
2
Answers
Well, to answer my own question, in case anyone needs the same:
I ended up finding a good code conversion tool and it gave me the following asp.net code that works just fine:
Typically a standard, clean XML is like this:
Hence, for your XML, please
-
from the following :remove the
<?xml version="1.0" standalone="true"?>
line (or change to<?xml version="1.0" encoding="UTF-8"?>
)For sure you need to set the XML file to be writable otherwise the PHP will not be able to update and save the file.
So the following works (tested – 2nd record Status updated from
In
toOut
):XML
PHP (as a test I hardcoded the variables to be set by POST)
Last but not least, one seldom uses
location.reload();
on success from a ajax call (just a note)