• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

PHP replacing new value in a text file

Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Posts: 3648
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well first you need to "read" the values and add the new value
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
<html xmlns="http://www.w3.org/1999/xhtml">;
<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;

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you ever get your edit fruit quantity PHP code /page going?

Can you share the final code please.

I'm having trouble applying the above snippets to a form based on a 4-line text file to a quantity-edit web form project similar to yours maybe.

[Thumbnail for fruitform.png]
Sample edit value form.
I'm still in control here. LOOK at this tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic