使用表单提交覆盖txt文件上的变量

时间:2015-02-02 20:25:15

标签: php forms file form-submit increment

我试图做的是当用户点击增量按钮时,$ var存储在File.txt中变为$ var + 10这就是我得到的:

first.php代码:

 <?php $myFile = "File.txt";
 $fh = fopen($myFile, 'r');
 $theData = fread($fh, 5);
 fclose($fh);

 ?>

这是主页面代码:

 <?php  

       include 'first.php';

       $var = $theData + 10;

  $myFile = "File.txt";
   $thetext=$_POST['sometext'];
   writemyfile($myFile,$thetext,"w");


  function readmyfile($thefile)
  { 
  $myfile=fopen($thefile,"r");
  $x = fread($myfile, filesize($thefile));
  fclose($myfile);
  return $x;
    }

  function writemyfile($thefilename,$data,$mode)    
  {
  $myfile=fopen($thefilename,$mode);
  fwrite($myfile,$data);
  fclose($myfile);
  } 

  ?>
      <html>
      <head>
      <title>Example of a form</title></head>
      <form method="post" action="<?php echo $php_self ?>">
      <input type="hidden" name="sometext" value="<?php echo $var ?>" >
      <input type="submit" name="Submit" value="increment">
      </form>

      </html>

问题是我每次刷新主页面时都没有点击File.txt上的值的增量按钮。

0 个答案:

没有答案