SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My first try with manipulating any kind of flat files... I've always used databases. But here was my first shot... because I don't need a database for one text file that's going to change like i once a week.

    Here is my code:

    Code:
    <?php
    $filename = "/home/username/domain-www/sixgunner/sixgunner.txt";
    
    if($submit == "Update"){
    
    $contents = addslashes($contents);
    $fd = fopen($filename, "w");
    fwrite($fp, "$contents");
    fclose($fp);
    
    echo("$contents");
    
    } else {
    
    $fd = fopen($filename, "r");
    $contents = fread($fd, filesize($filename));
    fclose($fd);
    
    ?>
    <form action="<?php echo("$PHP_SELF"); ?>" method="post"><textarea name="content"><?php echo("$contents"); ?></textarea><br>
    <input type="submit" value="Update" name="submit"></form>
    <?php
    }
    
    ?>
    This file is called update.php and also sits in the /sixgunner/ directory. All permissions are set properly. I get this error:

    Code:
    Warning: Supplied argument is not a valid File-Handle resource in /home2/bullets/beartoothbullets-www/sixgunner/update.php on line 8
    
    Warning: Supplied argument is not a valid File-Handle resource in /home2/bullets/beartoothbullets-www/sixgunner/update.php on line 9
    Any Ideas? I copied my entire code so you can see it... in it's entirity.

    God Bless, and thanx!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hope you are sitting down - you are either going to laugh or cry over this one:
    $fd = fopen($filename, "w");
    fwrite($fp, "$contents");
    fclose($fp);
    $fd != $fp

    May I suggest that you use more meainingful variable names
    (I know I tend to slip into the habbit of using things like $x -
    but - plain English variable names do tend to help readability
    and understandability of code. This also makes errors more obvious.
    Code:
    $file= fopen($filename, "w");
    fwrite($file, "$contents");
    fclose($file);
    Last edited by freakysid; Apr 4, 2001 at 23:47.

  3. #3
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanx

    I figured that out about 2:30 last night! And I almost cried... well, I did, I cried to my host... what's wrong with your PHP version, what idiot set this up.. etc... I sent them an appology... man, I'm still laughing!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


Bookmarks

Posting Permissions

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