Home arrow PHP arrow Page 2 - PHP Form to Text File: the Basics

Processing inputs from submitted form and writing the text to a file - PHP

This is a basic tutorial on the application of PHP to get text information from a web form and write it to a text file.

TABLE OF CONTENTS:
  1. PHP Form to Text File: the Basics
  2. Processing inputs from submitted form and writing the text to a file
  3. Code discussion
  4. Adding Four Features to the Basic Web Application
  5. Adding features, continued
By: Codex-M
Rating: starstarstarstarstar / 3
July 20, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
 

 

<?php

 

}

 

else

 

{

 

//Form submitted, grab the data from POST

$textinputs =trim($_POST['textinputs']);

 

//Test if it contains some data.

 

if (!isset($textinputs) || trim($textinputs) == "")

 

{

 

//Feedback to user that it contains no data

 

die ('ERROR: Enter your text. <a href="/phpformtotextfilebasic">Click here to proceed.</a>');

 

}

 

else

 

{

 

//Set file and the path to write

$filepath='/opt/lampp/htdocs/phpformtotextfilebasic/textfolder/writethistextfile.txt';

 

//Open file in writing mode

$filehandler= fopen($filepath, 'w') or die('ERROR: Could not open file!');

 

//Write text to file

 

fwrite($filehandler,$textinputs) or die('ERROR: Could not write to file');

 

//Close file

fclose($filehandler);

 

echo 'Your text has been written to the file successfully.<br />';

 

echo '<a href="/phpformtotextfilebasic">Enter another text.</a>';

 

}

 

}

 

?>

 



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: