aspose file tools*
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
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
Author

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?
Thanks

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2419
    
    7

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


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
sourav jain
Greenhorn

Joined: Nov 19, 2012
Posts: 22
hi

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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php

class ABC
{

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


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

global $totalorange,
$totalbnana,
$totalapples,
$total,
$totalitems;



$app=$apples;
$ban=$bannas;

$oran=$oran;


$totalapples=$app+$totalapples;
$totalbnana=$ban+$totalbnana;
$totalorange=$oran+$totalorange;
$totalitems=$totalorange+$totalbnana+$totalapples;
echo $total=$total+$totalitems;

$file=fopen("sourav.txt","w");

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

fclose($file);


}








}






$obj =new ABC;
$obj->fun(70,20,30);
//$obj->insert();
?>


</body>
</html>
 
Don't get me started about those stupid light bulbs.
 
subject: PHP replacing new value in a text file