I have an inc file that contains 4 MySQL database variables – hostname, database, username and password. These inc file is included in other php files to execute database queries.
What I would like to do is to create a form that can update this inc file so the MySQL variables can be changed. As a real novice I am not sure how to approach this, so any help is greatly appreciated.
Thank you very much.
You have to be very careful doing things like this, more often than not it allows people to hack and/or break your application.
What you need to do is simply overwrite your file with the new values – how you collect those values is up to you.
Lets assume that you’re collecting the values through a POST form submission from a web page, you could do something like this:
Hopefully that should get you started, but you will still need to do a lot of work, such as sanitizing the input, possibly testing whether the new details work before you overwrite your config file, including you config file afterwards to ensure that it works, etc etc.