Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts

    Write and Replace?

    I've never did this before so I would really like some help. I have a file named
    db.inc.php which holds the following code:
    PHP Code:
    <?php
    $dbusername 
    '';
    $dbpasswd '';
    $dbhost '';
    $database_name '';
    $database_prefix '';
    ?>
    I would like to know what code I would need to take info from a form and re-write the file so the code in it looks like:
    PHP Code:
    <?php
    $dbusername 
    'xxxxx';
    $dbpasswd 'xxxxx';
    $dbhost 'localhost';
    $database_name 'xxxxx';
    $database_prefix 'xxxxx';
    ?>
    In other words it would be kind of like a install script. Thanks.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Get all your form info, write it into a variable, save to file

    PHP Code:
    // form submitted
    $config = '<?php 
    $dbusername 
    '' $_POST['dbusername'] .'\'; 
    $dbpasswd = \'' 
    $_POST['dbpasswd'] .'\'; 
    $dbhost = \'' 
    $_POST['dbhost'] .'\'; 
    $database_name = \'' 
    $_POST['database_name'] .'\'; 
    $database_prefix = \'' 
    $_POST['database_prefix'] .'\'; 
    ?>'
    ;

    // do all your file writing here
    $handle fopen("db.inc.php","w+");
    fputs($handle,$config);
    fclose($handle);
    ?>

  • #3
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    alrighty, i'll give that a shot... thanks.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •