Hi just looking for some direction, I have a HTML form which has several fields and basically what I am wanting to do is save the data entered from the form to a PHP config file and also have the ability to edit the saved data by accessing and submitting the form again. I would prefer to do this without the use of a database.
So here’s an example:
<form method="post" name="config_form">
<div id="field">
<label>Keywords</label>
<br />
<input type="text" name="keyword">
</div>
<br />
<select name="color">
<option value="green">Green</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
<option value="red">Red</option>
</select>
</form>
So the user enters ‘computer’ as the keyword and selects the color ‘blue’. I want to then save this data into my config.php file as variables allowing my other website pages to access this data. Should this all be in an array as well?
<?php
//config file
$keyword = "computer";
$color = "blue";
?>
Also when I go back access the form again can I make it so the fields are prefilled with the data from the config.php file?
Any help would be much appreciated thank you!
You can include your configuration file in your main php script file:
and build the form with something like this:
finally you can save the form data in your
config.phpfile usingfopen()andfwrite()functions on form submit: