Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    writing to a txt file using the pipe symbol?

    i wrote this code to read from a text file using php, but when i go to add more info using a html form, it just adds the info but not in the right place.it needs to be in number order.


    Any help please......

    this is my text file:
    |1 |11|21|31|41|51|71|81
    |2 |12|22|32|42|52|72|82
    |3 |13|23|33|43|53|73|83
    |4 |14|24|34|44|54|74|84
    |5 |15|25|35|45|55|75|85
    |6 |16|26|36|46|56|76|86
    |7 |17|27|37|47|57|77|87
    |8 |18|28|38|48|58|78|88
    |9 |19|29|39|49|59|79|89
    |10|20|30|40|50|60|80|90

    this is the php file in which i use to read this file.

    <?php
    $file = fopen("welcome.txt", "r");
    if(!$file) {
    print "error! The file could not be opened";
    exit;
    }
    // read file and print, line by line


    while(!feof($file))
    {
    $text=fgets($file);

    if ($text!="M"&&$text!="F")

    {
    echo "$text
    ";
    }


    }
    fclose($file);
    ?>
    </body>
    </html>


    this is my append to file PHP script but isnt working right:

    <?php
    $customerName = $_POST['name'];

    if(!$customerName) // If name is not entered show error message
    {
    echo "Please enter your name to register.";
    exit;
    }
    else
    {
    $filename = "seats.txt"; // File which holds all data
    $content = "$customerName\n"; // Content to write in the data file
    $file = fopen($filename, "a"); // Open the data file, file points at the end of file
    $filewrite = fwrite( $file, $content ); // Write the content on the file
    fclose( $file ); // Close the file after writing

    if(!$filewrite) echo "Couldn't write the entry.";
    else
    echo "You are now registered, Click below to continue.";
    }
    ?>

    </body>
    </html>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Post your form, an example of what you're submitting, and the unintended result. Also, I don't see any code dealing with numbers at all. Are you manually entering them?


  •  

    Posting Permissions

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