how to store data from a html5 form to txt file using php

Tags: php
By : Chris

I am trying to use this HTML form to gather information from the end-user and save it using PHP to a text file. I am looking for various ways that I can accomplish this by assuming the text file does not exist and also checking and appending if the file does exist. Does anyone have any suggestions?

Html form:

<form id="newuser" method="post" action="newUser.php"> 
    <label for="name">Name</label>
        <input type="text" name="name" placeholder="Full Name">
    <label for="email">E-mail</label>
        <input type="email" name="email" placeholder="[email protected]">
    <label for="birthday">Birthday</label>                         
        <input type="date" name="birthday" min="1929-12-31">
    <label for="phone">Phone</label> 
        <input type="tel" name="phone" placeholder="ex. (555) 555-5555">        
    <label for="message">Question/Comment</label> 
        <textarea name="message"></textarea>
    <label>Check this box if you agree to the website 
      <a href="terms.php">terms</a> 
        <input type="checkbox" name="agreetoterms" value="Agree"> </label>
        <input type="submit" name="submit" id="submit" value="Join Now" />
  </fieldset> </form>
By : Chris


Make sure to set "read/write" permission to "all" in the server folder (htdocs if xampp) Security risk Easy to get hacked *** do it for educational pupose

        $name = $_POST["name"];
        $email = $_POST["email"];
        $birthday = $_POST["birthday"];
        $phone = $_POST["phone"];
        $message = $_POST["message"];
        $final ="Name: ".$name . "\nEmail: " . $email. "Birthday:  ".$birthday."Phone :".$phone."Message: ".$message;
        $fileWrite = fopen("storeFormData.txt","a");

I hope it Works

I don't really know what more to add so let's hope this gives more guidance to you to solve your problem with recording the user's form submission to a text file. Other than "checking" you simply can do as below

    /* newuser.php */

            A path to where you wish to store the file, preferably outside of the document root.
            The example path below is within the document root because there is no way of 
            knowing your directory structure.
        $saveto=$_SERVER['DOCUMENT_ROOT'] . '/folder/file.txt';

        if( !empty( $_POST ) ){

                Add the POSTed form contents to your file.

                >   The return of `file_put_contents` is the number of bytes written to the designated file.
                >   `print_r( $var, true )` makes the output suitable for writing to file.
                >   `FILE_APPEND` & `FILE_TEXT` are two of the possible options `file_put_contents` accepts and are suitable for your question

            $bytes = @file_put_contents( $saveto, print_r( $_POST, true ), FILE_APPEND | FILE_TEXT );

            /* Process the form data however you would normally */

By : RamRaider

This has happened to me a few times already i.e. when a binary doesn't finish processing due to connection drop or other issues (on apple side).

Just upload a new build and use that build for release or test flight. Don't worry about the build that never finishes. Just ignore it and move on.

If you are still seeing build 2 as the latest under testfligth section, then logout, clear your browser cache, log back in and see. Clearly your build 3 is the latest one. itunesconnect is super flaky.

Use apple support as a last resort. They will take days to solve something as simple as this.

By : Sam B

This video can help you solving your question :)
By: admin