Could use a little nudge in the right direction.

Discussion in 'PHP' started by ryandanielt, Apr 25, 2009.

  1. #1
    So I've been working on this little script but I am trying to accomplish something that seems to not be working.

    I have done this in one of my scripts some time ago but for some reason I can not get it to work now.


    I have created a php file named config.php and what I would like to do is enter a value into some variables in that file such ad dbhost and dbuser and dbpass using a basic form with basic text fields.

    Sample Config Layout.
    
    <? 
    $dbhost = 'Value to go here!';
    $dbuser = 'Value to go here!';
    $dbpass = 'Value to go here!';
    $dbuser = 'Value to go here!';
    ?>
    
    PHP:
    I have just tried to accomplish this using fwrite but since its been so long since I've done this I cant get it rite.


    I know there are many of you that do this on a daily basis so a little help would be greatly appreciated.


    Cheers!
     
    ryandanielt, Apr 25, 2009 IP
  2. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Something on the lines of...

    $file = 'config.php';
    $fh = fopen($file, 'w') or die('can't open config.php file chomd to 0777.');
    $filedata = "
    <?
    /$var1 = 'Something';
    /$var2 = 'Something2 etc...';
    ?>
    ";
    fwrite($fh, $filedata);
    fclose($fh);
    PHP:
     
    dannywwww, Apr 25, 2009 IP
  3. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #3
    That's what I am trying to use but its not working, this is the only method that I know of lol
     
    ryandanielt, Apr 25, 2009 IP
  4. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Are you sure your chmoded the config.php file?
     
    dannywwww, Apr 25, 2009 IP
  5. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Yea, I created it so far so that it creates the config file and sets the permissions to 777 and then it writes to it.
     
    ryandanielt, Apr 25, 2009 IP
  6. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #6
    You see, I even copied your code word for word and I receive the same result.

    
    
    <?
    /  = '1';
    /  = '1';
    ?>
    
    
    PHP:
    Is what shows up in the config file lol
     
    ryandanielt, Apr 25, 2009 IP
  7. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #7
    What about chaging:
    
    $filedata = "
    <?
    /$var1 = 'Something';
    /$var2 = 'Something2 etc...';
    ?>
    ";
    
    PHP:
    to

    
    $filedata = '
    <?
    $var1 = "something";
    $var2 = "Something2 etc...";
    ?>
    ';
    
    PHP:
    And if that does not work, why not use defines instead of variables, personal preference :-P
     
    dannywwww, Apr 25, 2009 IP
  8. ryandanielt

    ryandanielt Well-Known Member

    Messages:
    1,797
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    185
    #8
    Nope I get the same effect, for some reason any code that I have tried to get this to work does not insert anything that looks like a variable unless it has a value.

    I remember there was some way to do this but I cant remember.

    hmmmmmm
     
    ryandanielt, Apr 25, 2009 IP