Page 1 of 1

Can anyone help with this script

Posted: Wed May 17, 2006 7:51 am
by spudmclard
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Im trying to pass data entered into a form to a file 'file2.txt' and append that data in 'form1'.

[b]CODE FOLLOWS[/b]

Code: Select all

<?php
$name=$_POST['data'];
$file_name = "file2.txt"; 
$fp = fopen($file_name, "a");
 //write to the file
fwrite($fp, "$name");
fclose($fp);
$file_name2 = "file1.txt";
$fp2 = fopen($file_name2, "a");
$name = str_replace("$name","***");
?>
So far it succesfully writes to 'file2.txt' but it doesnt append the entry in 'file1.txt'
Any help would be greatly appreciated cos ive hit a massive brick wall with another one waiting close behind it :(


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed May 17, 2006 8:06 am
by shiznatix
Can anyone help with this script
short answer: 'no'

long answer:

you arn't writing to the 'file1.txt' so of course its not adding in anything. Is that what you wanted?

Posted: Wed May 17, 2006 8:08 am
by JayBird
Yup, as shiznatix has stated, you have simply failed to use fwrite() in the second instance

Posted: Wed May 17, 2006 8:12 am
by spudmclard
Ah

Just proves how stupid i can be......

ive added the following to the file but still no joy.

Code: Select all

$namec = str_replace("$name","***");
fwrite($fp2, "$namec");
As you can guess im struggling here, any help would be appreciated.

Posted: Wed May 17, 2006 9:28 am
by sheila
str_replace takes 3 arguments.
Also you don't need quotes around the variable names in your argument list, and watch the order of the arguments

Code: Select all

$namec = str_replace($search, $replace, $name);
$name is the string to be changed
$search is what we want to find
$replace is the new value to be substituted when $search is found

Have a look at the manual http://us2.php.net/str_replace for more details.