Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5

Thread: fwrite - PHP

  1. #1

    Default fwrite - PHP

    Hi,

    I currently have a script which writes to a file called pollinfo.php;

    PHP Code:
    <?php
    $vote 
    $_POST['group1'];
    if (
    $vote == '1')
    {
        
    $vote 'fifth';
        
    $file = @fopen("pollinfo.php""w");
        
    $data "\nOne vote for the $vote \n";
        @
    fwrite($file$data);
        @
    fclose($file);
    }
    else if (
    $vote == '2')
    {
        
    $vote 'thirteenth';
        
    $file = @fopen("pollinfo.php""w");
        
    $data "\nOne vote for the $vote \n";
        @
    fwrite($file$data);
        @
    fclose($file);
    }

    echo(
    "<br /><br />Thank you for sending in your opinion!");
        
    ?>
    However, every time someone votes, the poll overwrites the current data. Is there anyway to keep the current data and just continue as a new set of data, or would I have to open the file, read what it says, and add it to the $data variable?

    Regards,
    James.

  2. #2
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Why don't you use fopen to open the file, grab the data, and then append the new poll vote onto the end of the current information? You could store it like this

    1|0|1|0|0|1|1

    then explode it, and count the array for the total? I dunno, but you definatly need to use fopen.


    www.fragme.co = a project.

  3. #3

    Default

    Quote Originally Posted by Source View Post
    Why don't you use fopen to open the file, grab the data, and then append the new poll vote onto the end of the current information? You could store it like this

    1|0|1|0|0|1|1

    then explode it, and count the array for the total? I dunno, but you definatly need to use fopen.
    Yeah, that was my thought exactly.. Well thanks for your help, I'll try to fopen it store the data already in the file then replace the data with the additional data.

  4. #4

    Default

    Sorry for double post, but I've just found something called "Append (a)";

    Append: 'a'
    Open a file for write only use. However, the data in the file is preserved and you begin will writing data at the end of the file. The file pointer begins at the end of the file.

    A file pointer is PHP's way of remembering its location in a file. When you open a file for reading, the file pointer begins at the start of the file. This makes sense because you will usually be reading data from the front of the file.

    However, when you open a file for appending, the file pointer is at the end of the file, as you most likely will be appending data at the end of the file. When you use reading or writing functions they begin at the location specified by the file pointer.

  5. #5
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Jam-ez View Post
    Sorry for double post, but I've just found something called "Append (a)";
    Yes, that's what o need.
    PHP Code:
    @fopen("pollinfo.php""a"); 

Posting Permissions

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