Web Analytics Made Easy -
StatCounter Form to Text File - CodingForum

Announcement

Collapse
No announcement yet.

Form to Text File

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

  • Form to Text File

    I have this form
    Code:
    <body>
    <form>Username<br />
    <input name="name" type="text" size="30" /><br />
    Password<br />
    <input name="name" type="password" size="30" /><br />
    <input name="name" type="submit" value="Submit" /><input
    name="name" type="reset" value="Reset" /></form>
    </body>
    How can I make it post the user entered data to a text file (let's call it textfile.txt) but allow textfile.txt to have more than one entry and the page that it goes to when it is prossed shows the user entered data like
    Username - the username
    Password - the password


    Any help will be gratefully taken, thanks.
    Geoffrey Sneddon

  • #2
    first, change your html code to read:
    Code:
    <body>
    <form action="process.php" method="POST">
    Username<br />
    <input name="username" type="text" size="30" /><br />
    Password<br />
    <input name="password" type="password" size="30" /><br />
    <input type="submit" value="Submit" /><input type="reset" value="Reset" /></form>
    </body>
    then, in process.php:
    PHP Code:
    <?php

    /**** Dump the data to a text file ****/

    // the text file to store the information
    $datafile "textfile.txt";

    // open a file handle
    $my_file fopen($datafile,"a");

    //write teh data to the file
    fputs($my_file,"Username: " $_POST["username"] . " | Password: " $_POST["password"] . "\r\n",4096);

    // close the file handle
    fclose($my_file);


    /**** Display the information in the browser ****/
    print "<html>\n\n<body>\n\n";
    print 
    "Username: " $_POST["username"];
    print 
    "<br/>\n";
    print 
    "Password: " $_POST["password"];
    print 
    "<br/>\n";
    print 
    "</body>\n\n</html>";

    ?>
    I didn't include any error handling, but the rough code should work.

    Comment


    • #3
      Code:
      <body>
      <form action="process.php" method="POST">
      Username<br />
      <input name="username" type="text" size="30" /><br />
      Forum Username<br />
      <input name="forumusername" type="text" size="30" /><br />
      Password<br />
      <input name="password" type="password" size="30" /><br />
      <input type="submit" value="Submit" /><input type="reset" value="Reset" /></form>
      </body>
      I have changed the code, I will try to modify the php code myself and how could I make the title of the page it goes to "Form Submitted"?
      Geoffrey Sneddon

      Comment


      • #4
        Can someone check this incase I have mucked this code up.


        Update - I give up, vBulletin is adding in _ in my script.
        Last edited by gsnedders; Feb 16, 2004, 05:12 PM.
        Geoffrey Sneddon

        Comment


        • #5
          The code just gives this error
          Parse error: parse error in /home/b2l0963/public_html/developerslogin/process.php on line 21
          Line 21
          PHP Code:
          $datafile_=_"/developers/requests/index.txt"
          Geoffrey Sneddon

          Comment


          • #6
            Yea because what you've written doesn't make any sense.

            What're you trying to do? Just assign the string to the variable, or concatenate the string to the variable?

            Also what's the name of the variable? Like what do you have so many underscores all over the place?

            assign:
            PHP Code:
             $datafile "/developers/requests/index.txt"
            concatenate:
            PHP Code:
             $datafile .= "/developers/requests/index.txt"
            I'm not sure what you're trying to accomplish with all those underscores (_), but as far as I know, they are not an operator of any kind.

            Hope that helps,
            Sadiq.

            Comment


            • #7
              Originally posted by sad69
              Yea because what you've written doesn't make any sense.

              What're you trying to do? Just assign the string to the variable, or concatenate the string to the variable?

              Also what's the name of the variable? Like what do you have so many underscores all over the place?

              assign:
              PHP Code:
               $datafile "/developers/requests/index.txt"
              concatenate:
              PHP Code:
               $datafile .= "/developers/requests/index.txt"
              I'm not sure what you're trying to accomplish with all those underscores (_), but as far as I know, they are not an operator of any kind.

              Hope that helps,
              Sadiq.
              Oh, my computer must have been puting them in, done that before.
              Geoffrey Sneddon

              Comment


              • #8
                The Problem


                Parse error: parse error in /home/b2l0963/public_html/developerslogin/process.php on line 12
                The attachment is the folder with the fiels in.
                Attached Files
                Geoffrey Sneddon

                Comment


                • #9
                  What editor are you using?

                  I'm not sure what's going on exactly, but I'm seeing alot of weird characters, especially accented E's. These are in place of the underscores.

                  Once you figure out why you're getting all these weird characters thrown into your files, you may get some more concrete errors -- or it may just work fine

                  Hope that helps,
                  Sadiq.

                  Comment


                  • #10
                    I'm using BBEdit Lite
                    Geoffrey Sneddon

                    Comment


                    • #11
                      Maybe it's the line break format, I have a chose of Macintosh, *nix or DOS
                      Geoffrey Sneddon

                      Comment


                      • #12
                        I'm getting the same characters. I'm guessing the ت in your file is causing the error. Might be due to your pc set at a wrong chartype, but I'm unsure.

                        Comment


                        • #13
                          Did you mean choice? I would choose *nux.

                          What OS are you using? It must be your editor that's screwing things up for you. Also where is your server and PHP running? What OS is that running? It'll make a huge difference once you get rid of those weird characters.

                          If you're using Windows, I use a program called ultra edit that's pretty good. HTML-Kit is also good on Windows. You wouldn't have this problem on *nix I suspect, and I'm not familiar enough with Mac, but I'm sure they've at least got a simple text editor that will exploit the weird characters in your file.

                          Good luck,
                          Sadiq.

                          Comment


                          • #14
                            I'm running Mac OS 10.3.2
                            The server is running Linux
                            The server has PHP v.4.3.3
                            Last edited by gsnedders; Feb 16, 2004, 06:59 PM.
                            Geoffrey Sneddon

                            Comment


                            • #15
                              Attachment with file saved with the *nix line breaks.
                              Attached Files
                              Geoffrey Sneddon

                              Comment

                              Working...
                              X