473,503 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

edit text in a txt file

hi all,
here is the php code!

i am trying to use to 'edit' hyperlink to edit txt in member.txt.
Problem is that it reads the values ok into an array, however when i
attempt and update new values into the file, i get no results. Does
anybody know where i am going wrong????

<? session_start();
// Set updated content for user

if(!isset($_POST[Submit]))
{
// read content from file and place into array, this is used to put
initial content into form
$fc=file("../username/member.txt");
$userid_no = $_GET['record_id'];
$line = split("\|",$fc[$userid_no]);
$user_id = $line[0];
$password = $line[1];
$firstname = $line[2];
$lastname = $line[3];
$email = $line[4];

}
else
{
if(isset($_GET['record_id']))
{
// build record into string from post values
$update = $_POST['user_id'];
$update .= "|";
$update .= $_POST['password'];
$update .= "|";
$update .= $_POST['lastname'];
$update .= "|";
$update .= $_POST['firstname'];
$update .= "|";
$update .= $_POST['email'];
$update .= "|";
$update .= "";
$update .= "|";
$update .= "2";

$contents=file("../username/member.txt");
$fileName = "member.txt";
$edit_line = $_GET['record_id'];
$replace_text =$update;

// Strip carrage-returns
for($c = 0; $c < count($contents)-1; $c++)
{
$contents[$c] = str_replace( "\n", "", $contents[$c] );

}
//read file into array
//$contents = array($fileName);
//$contents = array($fileName);
// replace specified array index (user to update) with built string
$contents[$edit_line] = $replace_text;

// write array to file
if (!$fp = fopen($fileName,"w")) { die("Cannot open file"); }
// $contents = array($user_id,$password,$lastname,$firstname,$ema il);
// $contents= implode("|",$contents);
// $contents= chop($contents);
// $listf = fopen("member.txt", 'a+');
$count = 0;
foreach ($contents as $edit_line)
{

//fwrite($fp, $str);

if($count != $_GET['record_id']){
$str="\n".$contents[$edit_line];
fwrite($fp,$str);
}
$count++;
}
fclose($fp);
//header("Location:
}
}

?>

Apr 16 '07 #1
0 4481

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4252
by: matt | last post by:
I am using a text file as a database, each field delimited by || I want to be able to print all lines to a page, then by selecting one (with, say, a radio button) it will load into the form at the...
4
15547
by: Option^Explicit | last post by:
What I'm trying to do: Open a text file and display the contents in a text box (I've done this) Need to be able to edit the file from within the textbox and have it save back to the source...
4
10126
by: Abhishek | last post by:
Hi! I need to edit a text file. I need to replace a given text in the file with a new one. This text can exist anywhere in the file, so i first need to locate the text position and then edit...
0
3080
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
0
1754
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
4
3700
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
2
4162
by: Sin | last post by:
Hello everyone, I'm totally stumped at how little info I can find in MSDN or on the web concerning this. It's almost as if only microsoft personel hold the key to these secrets or something!!! ...
1
2150
by: ollielaroo | last post by:
Hi guys, Firstly I did do a search for this one first but I couldn't find anything related in this forum. I am using Dreamweaver MX and trying to build admin pages for an ASP site. My problem is...
1
2106
by: Xicon | last post by:
I am looking to create a program that is able to edit a text file that is not located within the program. This particular text file is always in the exact same location and is always named the exact...
0
1274
by: yemen2007 | last post by:
hi i have some problem in my project i want help . the problem it is update or edit to the file in xml.my project is write and update/edit to xml file. i done the first one is write bout i have...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.