Two Laptop Bag*
The moose likes PHP and the fly likes PHP replacing new value in a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "PHP replacing new value in a text file" Watch "PHP replacing new value in a text file" New topic

PHP replacing new value in a text file

Abhradeep Banerjee
Ranch Hand

Joined: Dec 09, 2009
Posts: 71
I have only put the PHP code I dont think HTML is needed as its quite a standard form.
I am kind stuck here. What i need to is everytime a user enters the no of oranges, apples and bananas this value be added on to what ever value there is in the text file currently.

in the text file if the user submits for the first time it will print out in the example below:

The total Number of Apples: 10
The total Number of Bananas: 10
The total Number of Oranges: 10

subsequent submission it will add on to the new value entered and it will replace the value 10 in this case.

Can someone assist in solving this problem?

K. Tsang

Joined: Sep 13, 2007
Posts: 2247

Well first you need to "read" the values and add the new value

sourav jain

Joined: Nov 19, 2012
Posts: 22

i have made class for insert the total number of apples, banana, oranges in file , i am using static variable instead simple variable. static variable preserve value all time .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>



class ABC

static $totalorange='';
static $totalbnana='';
static $totalapples='';
static $total='';
static $totalitems='';

function fun($apples,$bannas,$oran)

global $totalorange,



echo $total=$total+$totalitems;


fwrite($file,"the total oranges is".$totalapples);




$obj =new ABC;

I agree. Here's the link:
subject: PHP replacing new value in a text file
Similar Threads
How to retrieve value from .js and show the values in jsp ?
Retrieve data from other server using JavaScript
get value on click from table using javascript
Ajax and post messages
Display Result on Same Page?