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 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    36
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Exclamation

    This is the first time I've ever tried this so please bear with me. I created this with some html code:



    What I need this to do is when the person hits submit, it sends the text in each field to a file located on the web host. I need it to look something like this:


    Here's the code I have (not sure if it will help):
    Code:
    	<div id="welcom_pan">
    	<h2><span>submit your</span>VIDEO</h2><br>
    	<p><form>
    		YouTube Link to Video <br><input type="text" name="youtubelink" size ="50"/><br /><br />
    		Do you accept the rules (below)? <br><input type="radio" name="yes" value="yes" /> Yes <input type="radio" name="no" value="no" /> No<br /><br />
    		What's happening in the video?
    	</form>
    	<form method="post">
    		<textarea name="comments" cols="40" rows="5"></textarea><br>
    	</form><br>
    	<input type="submit" value="Submit" />
    	</p> 
    	</div>
    Anyone help?
    Last edited by ShaneC; 09-05-2011 at 11:03 PM. Reason: Merged bump post

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Okay and what have you tried? So far all we see is HTML code, what are you using to processing the input and write to a file?

  • Users who have thanked Fou-Lu for this post:

    Feriscool (09-05-2011)

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    36
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Okay and what have you tried? So far all we see is HTML code, what are you using to processing the input and write to a file?
    Alright, so I basically got it working, but there are couple things wrong with it. How can I make each new submission create the text from the fields on the next line in the output file?

    Code:
    <?PHP
    
    $filename = "output.txt"; #Must CHMOD to 666
    $quantity = $_POST['quantity'];
    $item = $_POST['item'];
    
    $fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
    if ($fp) {
    fwrite ($fp, $quantity . ", " . $item);
    fclose ($fp);
    echo ("Thank you for submitting your video!");
    }
    else {
    echo ("There was a problem submitting your video. Try again, or report the issue.");
    }
    
    ?>

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by Feriscool View Post
    Alright, so I basically got it working, but there are couple things wrong with it. How can I make each new submission create the text from the fields on the next line in the output file?

    Code:
    <?PHP
    
    $filename = "output.txt"; #Must CHMOD to 666
    $quantity = $_POST['quantity'];
    $item = $_POST['item'];
    
    $fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
    if ($fp) {
    fwrite ($fp, $quantity . ", " . $item);
    fclose ($fp);
    echo ("Thank you for submitting your video!");
    }
    else {
    echo ("There was a problem submitting your video. Try again, or report the issue.");
    }
    
    ?>
    Add a PHP_EOL constant to the string you are inserting: fwrite($fp, quantity . ', ' . $item . PHP_EOL);.
    Note that you probably want to open the file in append mode, not write mode.

  • #5
    New Coder
    Join Date
    Sep 2011
    Posts
    36
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Add a PHP_EOL constant to the string you are inserting: fwrite($fp, quantity . ', ' . $item . PHP_EOL);.
    Note that you probably want to open the file in append mode, not write mode.
    It's still not creating a new line in the output.txt file so that when the next person submits more text in the forms, it just over-writes the existing text.

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    51
    Thanks
    6
    Thanked 12 Times in 12 Posts
    PHP Code:
    $fp fopen ($filename"w"); 
    change that to
    PHP Code:
    $fp fopen ($filename"a"); 
    according to fou-lou, that should fix it.


  •  

    Posting Permissions

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