Change information in a external txt file "onclick"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Change information in a external txt file "onclick"

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Hey thx a lot... :)
i though i was able to call the code within the same page though :/ but thx :):)
Post Reply