Web Analytics Made Easy -
StatCounter Need help with this form to text script - CodingForum

Announcement

Collapse
No announcement yet.

Need help with this form to text script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with this form to text script

    Here is the script I am using:

    PHP Code:
    <?php
    if($_POST)

    {

    $fp fopen('pass.txt','w+');

    fwrite($fp,' textField= '.$_POST['Username']);
    fwrite($fp,' textField= '.$_POST['Password']);

    fclose($fp);

    }

    // display form:
    else {
    ?>
    <form action="<?php htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES); ?>" method="POST">
    Enter your Username: <input type="username" name="Username" />
    Enter your password: <input type="password" name="Password" />
    <input type="submit" />
    <?php ?>
    I got it to submit the form results successfully to the text file, but as soon as the next person submits via the same form, the old information gets overwritten with the new info.

    Here is an example of what gets written into the text file:

    textField= username textField= pass
    Then when someone submits the form again, the old text file results get erased and the new info is put in:

    textField= username2 textField= pass2
    I want to make it list the results like this:

    textField= username textField= pass
    textField= username textField= pass
    textField= username textField= pass
    textField= username textField= pass
    rather than erasing the previous insertion.

  • #2
    rather than opening the file with 'w+', use 'a+' instead (for 'append' I assume...) and the new contents will be added after the current ones.

    The php manual page has more information: http://uk.php.net/fopen
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

    Comment

    Working...
    X