www.webdeveloper.com
Results 1 to 2 of 2

Thread: fputcsv

  1. #1
    Join Date
    Apr 2014
    Location
    I live in Canada
    Posts
    3

    Smile fputcsv

    HI

    I hoping that someone will be able to tell me why I am not able to write to my csv file.

    Here is my csv file (check.csv):

    check, 1

    My first php file (qaz.php) changes the value of 1 to 0:

    <?php
    $handle = fopen ( "check.csv", "rw" );
    while( $data = fgetcsv($handle, 1000, ",")) {
    echo 'varA = ' . $data[0] . "<br>";
    echo 'varB = ' . $data[1] . "<br><br>";
    if ( $data[1] == 1 ) {
    $data[1] = 0;
    fputcsv( $handle, $data[1] );
    echo 'varA = ' . $data[0] . "<br>";
    echo 'varB = ' . $data[1] . "<br>";
    }
    }
    fclose ( $handle );
    ?>

    I can see the change with this php file, but when I load my second php, there is no changes.

    My second php file (qaz2.php) to see if the check.csv changed:

    <?php
    $handle = fopen ( "check.csv", "r" );
    while( $data = fgetcsv($handle, 1000, ",")) {
    echo 'varA = ' . $data[0] . "<br>";
    echo 'varB = ' . $data[1] . "<br><br>";
    }
    fclose ( $handle );
    ?>

    Thanks for your help.

    Ren

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    802
    Hmmm....

    Where did you get this syntax:
    PHP Code:

     $handle 
    fopen "check.csv""rw" ); 
    I don't see that in the manual.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles