• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PHP replacing new value in a text file

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

 
K. Tsang
Bartender
Posts: 3521
16
Android 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
 
sourav jain
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Ashton Cohen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhradeep

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.

fruitform.png
[Thumbnail for fruitform.png]
Sample edit value form.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic