Current location: Hot Scripts Forums » General Community » Script Requests » PHP write to text file

PHP write to text file

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 02-28-04, 12:25 PM
veeco veeco is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
PHP write to text file

I came up with this php script to get 3 fields from an HTML form. I want the text field "name" to be the name of the txt file to write to. Here is my code:

<?php
$name = @$_POST["name"];
$file = "$name" . ".txt";
$v1 = @$_POST["v1"];
$v2 = @$_POST["v2"];


// Set the string to be written to the file
$values = "&v1=$v1\r\n";
$values .= "&v2=$v2\r\n";

// Open the file for truncated writing
$fp = @fopen($file, "w") or die("Couldn't open $file for writing!");
$numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!");

@fclose($fp);
echo "Wrote $numBytes bytes to $file successfully!";

?>

$file is the name of the file. So if $name is aaron, it will write to aaron.txt, but my code is wrong, and I don't know how to fix it (I'm very new to php). Can anyone help?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 4 11-18-08 07:23 AM
How to write a php script to load a text file into a table automatically? xmxpcom PHP 2 02-12-04 09:37 AM
php write to file tiny Script Requests 2 01-14-04 10:12 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 08:19 PM
PHP - Dir listing and write to file NickyWhicko PHP 4 08-24-03 03:42 AM


All times are GMT -5. The time now is 03:37 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.