简体   繁体   中英

created html form to edit xml file but cant read php script

I created php file to edit xml file from html but when I run the script in browser ,that code is write as text like this

screenshoot

load("place.xml");
$rootTag = $xml - > getElementsByTagName("place") - > item(0);
$dataTag = $xml - > createElement("ano");
$wilayahTag = $xml - > createElement("wilayah", $_REQUEST['wilayah']);
$latitudeTag = $xml - > createElement("latitude", $_REQUEST['latitude']);
$longitudeTag = $xml - > createElement("longitude", $_REQUEST['longitude']);
$descTag = $xml - > createElement("desc", $_REQUEST['desc']);
$dataTag - > appendChild($wilayahTag);
$dataTag - > appendChild($latitudeTag);
$dataTag - > appendChild($longitudeTag);
$dataTag - > appendChild($descTag);
$rootTag - > appendChild($dataTag);
$xml - > save("place.xml");
} ?>

with 4 edittext

Here is my code

 <html> <head> <title>Add Location</title> </head> <body> <?php if(isset($_REQUEST['ok'])) { $xml = new DOMDocument("1.0"); $xml->load("place.xml"); $rootTag = $xml->getElementsByTagName("place")->item(0); $dataTag = $xml->createElement("ano"); $wilayahTag = $xml->createElement("wilayah",$_REQUEST['wilayah']); $latitudeTag = $xml->createElement("latitude",$_REQUEST['latitude']); $longitudeTag = $xml->createElement("longitude",$_REQUEST['longitude']); $descTag = $xml->createElement("desc",$_REQUEST['desc']); $dataTag->appendChild($wilayahTag); $dataTag->appendChild($latitudeTag); $dataTag->appendChild($longitudeTag); $dataTag->appendChild($descTag); $rootTag->appendChild($dataTag); $xml->save("place.xml"); } ?> <form action="index.php" method="post"> <input type="text" name="wilayah"/><br> <input type="text" name="latitude"/><br> <input type="text" name="longitude"/><br> <input type="text" name="desc"/> <input type="submit" name="ok" value="add"/> </form> </body> </html> 

It looks like the php code that you have entered is not being run as php. This probably means you don't have it located on a server when you opened it. I copied the code onto my server and it did work, displaying just text boxes and no code.

A file named place.xml with a <place> xml element must also be provided for this to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM