Click to See Complete Forum and Search --> : Making a form config page
comptech520
09-06-2007, 01:35 PM
Hi.
I have a file called config.php
I want to make a form to edit the variables.
One the form I want to have a save button.
What code do I use on the in the save button to make the changes on the config.php file?
Thanks
ellisgl
09-06-2007, 01:50 PM
Make an html form. On post do an fopen with 'w' and process the post data to make your config.php file.
comptech520
09-06-2007, 02:23 PM
Can you please give me a code example?
Thanks
ellisgl
09-06-2007, 02:45 PM
<?php
if($_POST)
{
$fp = fopen('myconfiguration.php', 'w') or die('Could not open file');
$conf = '<?php
$seta = \''.$_POST['a'].'\';
$setb = \''.$_POST['b'].'\';
?>';
fputs($fp, $conf) or die('Could not write to file');
echo 'Configuration has been updated.';
}
else
{
?>
<form action="" method="POST">
Setting A: <input type="text" name="a" /><br />
Setting B: <select name="b">
<option>1</option>
<option>2</option>
<option>3</option>
</select><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
?>