Page 1 of 1

Change information in a external txt file "onclick"

Posted: Mon Aug 18, 2003 10:16 am
by Draco_03
Hi, i tested a code to add and print information of a texte file... it works now what i wanted to do is on a click, add something or on click erase the file content...

this was my code

Code: Select all

<?php
$filename = "includes/fichier.txt";
$fp = fopen( $filename, "w" ) or die("$filename not found"); 
fwrite( $fp, "Hello world\n" ); 
fclose( $fp );
$fp = fopen( $filename, "a" ) or die("$filename not found"); 
fputs( $fp, "And another thing\n" ); 
fclose( $fp ); 

if (!$file = fopen("includes/fichier.txt","r")) &#123;
echo "Can't open the $filename";
exit;

&#125; else &#123;
	while(!feof($file)) &#123;
		$Ligne = fgets($file,50000);
		echo $Ligne;
		$Fichier .= $Ligne;	 
	&#125;
	fclose($file);
&#125;
?>
i created this function... and what i want is when i click on a hyperlink i want it to add the content (in this case $zip is an array).

Code: Select all

function write() &#123;
$file = fopen("includes/clients.txt","a");
fputs($file, "\n"); 
fputs($file, $zip);
fclose($file);
&#125;
so basically i ll need to put an onclick="" .. but i don t know what to put there...

ps : i m not familiar with php at all...not yet :)

thx

Posted: Mon Aug 18, 2003 10:21 am
by JayBird
Basically, you need to put

Code: Select all

onclick="link_to_file_that_has_the_code_to_add_the_content"



So, if you had a file called add_content.php that contained your code for adding information to the text file, your onlick bit would be

Code: Select all

onclick="add_content.php"
add_content could then automatically redirect you back to the original page, if that is what you wanna do

Mark

Posted: Tue Aug 19, 2003 9:18 am
by Draco_03
Hey thx a lot... :)
i though i was able to call the code within the same page though :/ but thx :):)