Imad Posted March 8, 2008 Share Posted March 8, 2008 Hi guys, I'm creating an installer for one of my scripts but I'm having some troubles. In the config file I have this: $host = 'localhost'; $dbuser = ' '; $dbpass = ' '; $db = ' '; From the installer, I want my users to be able to modify the values of the above variables through input boxes, with each variables values in each input box. How can I do this? Kind Regards. Link to comment https://forums.phpfreaks.com/topic/95082-need-help-with-vairables/ Share on other sites More sharing options...
BlueSkyIS Posted March 8, 2008 Share Posted March 8, 2008 reading and writing to file, you may want to look into fopen(), fread(), fwrite(), fclose() Link to comment https://forums.phpfreaks.com/topic/95082-need-help-with-vairables/#findComment-487040 Share on other sites More sharing options...
Imad Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks for your reply, I'll give it a whirl. Kind Regards. Link to comment https://forums.phpfreaks.com/topic/95082-need-help-with-vairables/#findComment-487044 Share on other sites More sharing options...
Imad Posted March 8, 2008 Author Share Posted March 8, 2008 fread() doesn't work when I try to list a variables value. Instead it lists the file by size. Any other ideas? Link to comment https://forums.phpfreaks.com/topic/95082-need-help-with-vairables/#findComment-487059 Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 try this. It assumes the file is "config.inc.php" <?php $host='localhost'; $dbuser='myusername'; $dbpass='secretstuff'; $db='mydbname'; ?> <?php if (isset($_POST['sub'])) { // update the config file $str = "<?php\n"; foreach ($_POST as $k=>$v) { if ($k != 'sub') // ignore submit button { $str .= "\$$k='$v';\n"; // add line to config file text } } $str .= '?>'; file_put_contents('config.inc.php', $str); exit ('Config file updated'); } include 'config.inc.php'; ?> <form method='post'> Host name <input type="text" name="host" value="<?php echo $host?>"> <br/> DB User <input type="text" name="dbuser" value="<?php echo $dbuser?>"> <br/> Password <input type="text" name="dbpass" value="<?php echo $dbpass?>"> <br/> Database <input type="text" name="db" value="<?php echo $db?>"> <br/> <input type="submit" name="sub" value="Update"> </form> Link to comment https://forums.phpfreaks.com/topic/95082-need-help-with-vairables/#findComment-487124 Share on other sites More sharing options...
Imad Posted March 8, 2008 Author Share Posted March 8, 2008 Thanks, it worked. Link to comment https://forums.phpfreaks.com/topic/95082-need-help-with-vairables/#findComment-487313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.