Jump to content

Updating and deleting from XML file?


mallister

Recommended Posts

Hi there, i have this assignment that is due tommorow, i have to make an application for a hiking organisation. And this is the first time I'm coding by myself from scratch. Problem:I have users that have to be able to apply for membership in groups of users, and their application must be granted by admin. In my database membership is in one table that conects table 'user' and table 'group'. I was thinking about having one xml file that would be updated by php script when user applies, and then later admin would read from that xml file, he would get user name and grup name that were saved when user clicked apply, and would be able to click on YES or NO, and the entry would be deleted from xml file. It seemed pretty simple to me until i relised that i have NO IDEA how to update or delete xml using php, an hour of googling and reading got me nowhere, im only more confused. I know how to work with database from php, i just need this xml part explained ,or link to nice and clear, row by row explanation/tutorial. OR i need different idea on handling that application system. :)

Link to comment
Share on other sites

There's nothing you can learn about XML overnight.You have to learn XML DOM to access and manipulate nodes, and once you know it you can use it with PHP's DOMDocument class.The W3Schools XML DOM tutorial tutorial displays it like this:xmlDoc.getElementsByTagName('item')[0].firstChild.nodeValuePHP's DOMDocument class uses it like this:$xmlDoc->getElementsByTagName('item')->item(0)->nodeValueThe main differences between PHP's implementation and the Javascript implementation is this:

  • PHP can't access nodes from a nodelist without the item() method, Javascript can access them as an array element with [].
  • In Javascript, to access the text in an element node you have to get the nodeValue property of the first child, which is a text node.PHP uses the nodeValue property of the element node itself to get the text.

Link to comment
Share on other sites

As you are using database to store user information you can do that in your database rather than seprate XML file. I think that would be more simpler to. you can add a column as APPROVED (bool type) in user table. when user will register by default it will be false. after that admin can change it it true where user membership will be greanted. other than that you can delete that row or make it awaiting.

Link to comment
Share on other sites

@birbal That would be soo nice, i know :) but i've got strict instructions not to modify database. And now i know why. Bstrds. ^^@Ingolme I guess I'll try Javascript, but after a BIG cup of coffee. thnx people.

Link to comment
Share on other sites

OMG i got it! :) 'Membership' table has columns for starting and ending date of membership, and those clumns are not required. So when user aplies Ill just insert row without dates.Then later admin wil query for rows without dates and will be able to set dates - grant membership. I can't believe i lost hours for that!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...