0
How can I save data in XML file but the data will be coming from input fields?
The input are about register form
2 Antworten
+ 3
An SQL database is much more commonly used for storing registration details than an XML file but a flat file database can work too.
If you were using PHP, you could copy everything from this tutorial:
https://www.tutorialrepublic.com/php-tutorial/php-mysql-login-system.php
Then replace all db connection, reads, and writes with PHP functions that manage user information with your XML file. You could structure the file like:
<users>
<user id="1" username="john" passwordHash="8725s6a87fafnas8d7" createdAt="2020-08-22">
</users>
I would use a repository design pattern to represent all users, with a PHP class representing a single User, and make it easy to access the user information in various ways. You could then talk with this repository's functions from many places instead of accessing the XML file from various parts of your project. Your repository should read all users from the file, handle all Create, Read, Update, Delete(CRUD) operations on users, and be able to save them back to the file.
That repository would be important for when you implement a login and other features involving the current user.
If you insist on an XML file for a project that is heavily accessed, you'll need to also lock the XML file between the read and write operations to prevent concurrency problems when more than 1 request updates user data in parallel. You'll have to test this thoroughly.
0
Thank sir