Jump to content

need help with vairables


Imad

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.