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
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post

    Question Appending PHP file with variables

    I'm trying to take data from a form and write them to a file 'config.inc.php' but without any luck.

    The data is required to set up the configuration of a forum I'm building the installer for.

    Below is my current code:

    PHP Code:
    $sFilename "../config.inc.php";
    $sData "\n\n// The following is from the install setup\n\n";
    $sData .= "\$sPWBBName = ".$this->sBoardName."\n\n";
    $sData .= "\$sSqlServer = ".$this->sDBHost."\n";
    $sData .= "\$sSqlUser = ".$this->sDBUser."\n";
    $sData .= "\$sSqlPassword = ".$this->sDBPass."\n";
    $sData .= "\$sSqlDb = ".$this->sDBName."\n\n";
    $sData .= "\$sTemplatePath = \"templates\"\n";
    $sData .= "\$sIncPath = \"incs\"\n\n";
    $sData .= "\$sPrefix = ".$this->sDBPrefix."\n";
    // Lets write the data
    $this->write_data($sFilename$sData);

    //Below is the function to write the data to the file...
    function write_data($filename$data)
    {
    //Appends file
    $handle fopen($filename"a");
    $finalwrite fwrite($handle$data);
    fclose($handle);
    return 
    true;

    Every time I try and run this, there doesn't appear to be any problems, apart from that it just won't write the data to the end of the file.

    Does anyone have any idea as to what's going on? and do i need to add the end '?>' to the document?

    Would it be easier to write a new php file to store the variables in?

    Many thanks in advance
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    try some basic error checking ..

    PHP Code:
    <?
    if( !is_writable$filename ) ){
        die( 
    $filename .' is not writable' ) ;
    }
    ?>
    + if on win32 try $handle = fopen($filename, "ab");
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post

    Smile Thanks

    Worked a bit on it after you posted, and the error messages pointed me in the direction that I needed to go.

    Cheers
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."


  •  

    Posting Permissions

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