Jump to content

Edit XML With PHP


acondiff

Recommended Posts

I am designing a portfolio website for a photographer and I wanted to create an admin system for him to edit the flash website.

 

My main question concerns the pricing page. I want to load the following XML into flash with as3:

<pricing>
<package>
<name>Package 1</name>
<price>$750</price>
<description>This is a description of package 1.</description>
</package>
<package>
<name>Package 2</name>
<price>$1250</price>
<description>his is a description of package 2.</description>
</package>
<package>
<name>Package 3</name>
<price>$1750</price>
<description>his is a description of package 3.</description>
</package>
</pricing>

So I want to be able to edit this data with PHP. There would be fields for each value with the value in the field.

 

Package:

Name:______________

Price:_______________

Description:

____________________

____________________

____________________

 

Also I want to be able to add and re-order packages.  So there would be an "Add Package" button that adds a group of fields.

 

Is this difficult to do? Sorry I am still learning PHP so any help would be greatly appreciated. =)

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/204815-edit-xml-with-php/
Share on other sites

Ok I found a solution to read the xml: http://condiffphotography.com/xmledit.php

 

<h2>Edit Pricing</h2>
<form>  
<?php
  $doc = new DOMDocument();
  $doc->load( 'pricing.xml' );
  
  $pricing = $doc->getElementsByTagName( "package" );
  foreach( $pricing as $package )
  {  
  $titles = $package->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;
  
  $prices = $package->getElementsByTagName( "price" );
  $price = $prices->item(0)->nodeValue;
  
  $descriptions = $package->getElementsByTagName( "description" );
  $description = $descriptions->item(0)->nodeValue;
  
  echo "
  <div style=\"padding:20px\">
  Package:<br />
  Title: <input type=\"text\" value=\"$title\" name=\"title\" />
  <br />
  Price: <input type=\"text\" value=\"$price\" name=\"price\" />
  <br />
  Description: <br />
  <textarea name=\"description\" />$description</textarea><br />
  <input type=\"button\" name=\"remove\" value=\"Remove Package\"><br />
  </div> 
  ";
  }
  ?>
  <input type="button" name="add" value="Add Package"><br />
  <input type="submit" name="mysubmit" value="Submit">
  </form>

 

I just need this form to be functional.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/204815-edit-xml-with-php/#findComment-1072269
Share on other sites

This is the wordpress admin system I created in the functions.php file that I was using this for. It loads the form values in from an xml file.

 

pricing-admin.png

 

The only thing thats not functional is, it doesn't save the data entered. I can add, remove, and edit the packages on the page, but it won't save it to the xml file it loads from. If anyone can lend me a hand that would be great!

Link to comment
https://forums.phpfreaks.com/topic/204815-edit-xml-with-php/#findComment-1072814
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.