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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.