changing old values to new values

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I just would like to re-explain the problem i am having as i had not
received any posts, so i might of explained in poorly.

The problem i am having is NOT parse error related, more or less a
problem in my logic. Ok , well what is happening is i am getting my
values in member.txt fields ok from reading it, but when i attempted
to write those values back to the member.txt file with updated string
values, my member.txt file is cleared of all values, and i think my
array is been wiped.

Here is the updated code:


//Store profile in username.txt
$fileName .= "../username/member";
$fileName .= $_POST['user_id'];
$fileName .= ".txt";
$handle = fopen($fileName, "w");
fwrite($handle, $_POST['form1']);

// build record into string from post values
$update = $_POST['user_id'] . "|" . $_POST['password'] . "|" .
$_POST['lastname'] . "|" . $_POST['firstname'] . "|"

$fileName = "../username/member.txt";
//set line to edit
//get file into an array
//set the file name

$edit_line = $_GET['record_id'];
//replace original record with new record
$replace_text =$update;

// replace specified array index (user to update) with built string
$contents[$edit_line] = $replace_text;
// Strip carrage-returns
for($c = 0; $c < count($contents)-1; $c++)
$contents[$c] = str_replace( "n", "", $contents[$c] );

// write array to file
if (!$fp = fopen($fileName,"w")) { die("Cannot open file"); }



// read content from file and place into array, this is used to put
initial content into form
$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];



Re: changing old values to new values

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

you do realize that this may be your problem?

it should be str_replace("\n", '', $contents[$c]) ...otherwise, you're just  
stripping the letter 'n'. likewise, later when you implode $contents, you  
concatenate the records with the letter 'n' again. what i don't understand  
is why you are stripping \n anyway since you implode using \n. why not just  
make $update/$replace_text end with \n, replace the correct element and be  
done with it. your implode can simply implode('', $contents)...since \n is  
already inclusive given that you use file().

does that help?  

Re: changing old values to new values

On 19.04.2007 03:02 programming wrote:
Quoted text here. Click to load it

The wheel you're trying to invent is called "database" and it would be  
wise to use an existing one (mysql, sqlite etc) rather than code your own.

gosha bine

extended php parser ~
blok ~

Site Timeline