Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php write to file????
Old 08-08-2004, 01:13 PM php write to file????
Junior Talker

Posts: 1
Trades: 0
i've been searching google for ages and cannot find anything about this that i can understand. basically what i want to know is what is the basic html/php code to write a forms contents to a .txt or .html file.
sazn is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-08-2004, 05:17 PM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
I'm assuming you don't have a great understanding of either PHP, or HTML forms. As such, this is a complete example. It will create a file called "input.htm" and fill it with the information from the form. It will erase any existing data within the file as well.

PHP Code:
<?php
if(isset($_POST['f_name'])) {
  
// Below we start off with some HTML
  
$out "<html>\n<head>\n<title> Stuff from form </title>\n</head>\n";
  
  
$out.= "<body bgcolor=\"#FFFFFF\">\n";
  
$out.= "<b>Name:</b> ".$_POST['f_name']."<br>\n";
  
$out.= "<b>Age:</b> ".$_POST['f_age']."<br>\n";
  
$out.= "<b>Hair Colour:</b> ".$_POST['f_hair']."<br>\n";
  
$out.= "</body>\n</html>";

  
// Create / open the file for "w" (writing)
  
$fp fopen("input.htm","w");

  
// Put the contents of $out into the file opened with $fp
  
fwrite($out,$fp);

  
// close the file
  
fclose($fp);
}
?>
Then, just below that, Put this code;

HTML Code:
<html>
<head>
<title> The form </title>
</head>
<body bgcolor="#FFFFFF">

<form method="POST" action="<?php echo $PHP_SELF; ?>">
Your name <input type="text" name="f_name"><br>
Your age<input type="text" name="f_age"><br>
Your hair colour<input type="text" name="f_hair"><br>
<input type="submit" value="save info"><br>
</form>

<a href="input.htm" target="_blank">Read the input.htm file</a>
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE

Last edited by webwoRRks; 08-08-2004 at 05:18 PM.. Reason: typo
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 12-11-2005, 09:25 PM Ok it works for me, but...
Junior Talker

Posts: 1
Trades: 0
webwoRRks


I took your example and used it, but all I wanted to do was erase a file, an error.log file

Heres what ive broken it down to and it works fine, its just for that one text box that I dont want to show, how do I get rid of that and still keep it working..

when I delete this line the text box is gone but the script no longer erases:

<br><input type="text" name="f_name"><br>


PHP Code:
if(isset($_POST['f_name'])) { 
  
// Create / open the file for "w" (writing) 
  
$fp fopen("error.log","w"); 
  
// erase the file 
  
fclose($fp); 

HTML Code:
 
<center><form method="POST" action="<?php echo $PHP_SELF; ?>">
<br><input type="text" name="f_name"><br>
<input type="submit" value="Press to Clear Log!">
</form>
<a href="error.log" target="_blank">View error.log in Browser Window</a></center><br>
 

thanks in advance
seboyd2000 is offline
Reply With Quote
View Public Profile
 
Old 12-12-2005, 01:25 PM
eburza's Avatar
Super Talker

Posts: 122
Name: Antonio Magdic
Location: Zagreb, Croatia
Trades: 0
just a tip:

make shore that u can rw to folder where u wanna create files ...

also make shore that u can rw file whic u wanna edit or delete!

use chmod!!! 644 ... (best for web)
__________________

Please login or register to view this content. Registration is FREE
eburza is offline
Reply With Quote
View Public Profile Visit eburza's homepage!
 
Reply     « Reply to php write to file????
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36164 seconds with 12 queries