#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    1
    Rep Power
    0
    I'm trying to run an integrated Flash interface/PHP script to take a questionaire, and I am quite frustrated by its nonworkitude.

    What happens is Flash exports a variable based on button selection to the php script, which runs through it and writes the result to a text database. This database supposedly tracks the total number of responses for each answer. Flash then calls back the result and displays it graphically.

    I'm fairly certain the Flash aspects of this are all just right. So the problem must be in the script. Here is the script:

    <?php

    // read the data into an array

    $temp=file("poll.txt");
    $poll[0]=0;
    $poll[1]=0;
    $poll[2]=0;
    $poll=explode("|",$temp[0]);
    switch ($choice) {
    case 1:
    ++$poll[0];
    break;
    case 2:
    ++$poll[1];
    break;
    case 3:
    ++$poll[2];
    break;
    }

    // write the updated stuff to the file

    $fp=fopen("poll.txt","w+");

    fputs($fp,$poll[0]."|".$poll[1]."|".$poll[2]);
    fclose($fp);
    // send the total back to Flash

    $total=$poll[0]+$poll[1]+$poll[2];
    if ($poll[0]>0)
    echo("value1=".(100*($poll[0]/$total))."&");
    else
    echo("value1=0&");
    if ($poll[1]>0)
    echo("value2=".(100*($poll[1]/$total))."&");
    else
    echo("value2=0&");
    if ($poll[2]>0)
    echo ("value3=".(100*($poll[2]/$total)));
    else
    echo("value3=0");
    ?>

    Someone suggested changing the switch statement to a simpler

    switch ($choice) {
    $poll[$choice - 1]++;
    }

    Anyway, the script does not appear to be writing correctly to the text file at all, every time the script runs the text file becomes simply

    | |

    and nothing else. I really don't know much of anything about PHP at this point, coming from the other end of things, but anyone who can help would be very much thanked.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    One thing I see wrong is your incrementing statements. The should be:

    $poll[x]++;

Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 10:45 PM
  2. php authentication not working
    By dmehler in forum Development Articles
    Replies: 2
    Last Post: February 20th, 2004, 12:44 PM
  3. got apche working, php not
    By adiwood in forum Apache Development
    Replies: 4
    Last Post: February 10th, 2004, 12:14 PM
  4. xslt_set_encoding() not working on Win PHP 4.3.3
    By esosa in forum PHP Development
    Replies: 0
    Last Post: February 3rd, 2004, 04:46 PM
  5. POST method not working in PHP.
    By coremah in forum PHP Development
    Replies: 4
    Last Post: January 26th, 2004, 03:32 PM

IMN logo majestic logo threadwatch logo seochat tools logo