Using php to create a form from a text file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hotrod57
    New Member
    • Oct 2007
    • 7

    #1

    Using php to create a form from a text file

    I am using php to write a function that reads in lines from a text file and creates a form with the corresponding input values. I have a text file that looks like this:

    title = Test Page
    checkbox = shoe
    checkbox = comb

    I can separate these lines into an array, ($array[0] = title, checkbox, checkbox, and $array[1] = Test Page, shoe, comb) but I can't seem to figure out how to get the function to print out each array with its value. For example: if my function reads the line "checkbox = shoe", I have the statement print ("<input type=checkbox name=userbox value=$check>$c heck");, which should print a checkbox on a form with its value being shoe. While testing, I got it to do that once, but it would only print out a checkbox with shoe like a million times on the page and never stop. It never reads the next line to see what the input will be. I tried to correct this, and now I can't even get it to print that out again. If anybody could help or show me where to get some help, it would be greatly appreciated. Here is where my code acts up:
    [code=php]
    <?php
    $data = file('test_read .txt');
    $line = explode("=", $data[1]);
    while ($line[0] == 'checkbox'){
    $check = $line[1];
    print ("<input type=checkbox name=userbox value=$check>$c heck");
    }
    ?>[/code]
    Last edited by pbmods; Nov 27 '07, 03:21 PM. Reason: Added CODE tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, HotRod.

    Looks like you have an infinite loop, because if $line[0] == 'checkbox', then there is no situation where $line[0] would ever NOT == 'checkbox'.

    Try using if instead of while.

    Comment

    Working...