Jump to content

PHP file not reading external files


hausnfranz

Recommended Posts

Hey all,

 

I had a friend put together a simple budget tracking page for me. However, I can't seem to get the PHP file to read the external text files where the data is stored. PHP is below. Each text file is named exactly how it is called in the php file.

 

thanks,

Nick

 

<?php
// $$ VARIABLE CHANGE IS NEEDED
$amountallowedA = 107;
$amountallowedB = 250;
$amountallowedC = 75;
$amountallowedD = 35;
$amountallowedE = 450;
$amountallowedF = 400;
$amountallowedG = 895;
$amountallowedH = 400;
$amountallowedI = 150;
$amountallowedJ = 30;
$amountallowedK = 70;

$fp = fopen("a.txt", "r");
$atotal = fread($fp, 1024);
fclose($fp);

$aresult = $atotal - $_POST[atotal];
if ($_POST[atotal] != ''){
$fp = fopen("a.txt", "w");
fwrite($fp, $aresult);
fclose($fp);
}

$fp = fopen("b.txt", "r");
$btotal = fread($fp, 1024);
fclose($fp);

$bresult = $btotal - $_POST[btotal];
if ($_POST[btotal] != ''){
$fp = fopen("b.txt", "w");
fwrite($fp, $bresult);
fclose($fp);
}

$fp = fopen("c.txt", "r");
$ctotal = fread($fp, 1024);
fclose($fp);

$cresult = $ctotal - $_POST[ctotal];
if ($_POST[ctotal] != ''){
$fp = fopen("c.txt", "w");
fwrite($fp, $cresult);
fclose($fp);
}

$fp = fopen("d.txt", "r");
$dtotal = fread($fp, 1024);
fclose($fp);

$dresult = $dtotal - $_POST[dtotal];
if ($_POST[dtotal] != ''){
$fp = fopen("d.txt", "w");
fwrite($fp, $dresult);
fclose($fp);
}

$fp = fopen("e.txt", "r");
$etotal = fread($fp, 1024);
fclose($fp);

$dresult = $etotal - $_POST[etotal];
if ($_POST[etotal] != ''){
$fp = fopen("e.txt", "w");
fwrite($fp, $eresult);
fclose($fp);
}

$fp = fopen("f.txt", "r");
$ftotal = fread($fp, 1024);
fclose($fp);

$dresult = $ftotal - $_POST[ftotal];
if ($_POST[ftotal] != ''){
$fp = fopen("f.txt", "w");
fwrite($fp, $fresult);
fclose($fp);
}

$fp = fopen("g.txt", "r");
$gtotal = fread($fp, 1024);
fclose($fp);

$gresult = $gtotal - $_POST[gtotal];
if ($_POST[gtotal] != ''){
$fp = fopen("g.txt", "w");
fwrite($fp, $gresult);
fclose($fp);
}

$fp = fopen("h.txt", "r");
$htotal = fread($fp, 1024);
fclose($fp);

$hresult = $htotal - $_POST[htotal];
if ($_POST[htotal] != ''){
$fp = fopen("h.txt", "w");
fwrite($fp, $hresult);
fclose($fp);
}

$fp = fopen("i.txt", "r");
$itotal = fread($fp, 1024);
fclose($fp);

$iresult = $itotal - $_POST[itotal];
if ($_POST[itotal] != ''){
$fp = fopen("i.txt", "w");
fwrite($fp, $iresult);
fclose($fp);
}

$jresult = $jtotal - $_POST[jtotal];
if ($_POST[jtotal] != ''){
$fp = fopen("j.txt", "w");
fwrite($fp, $jresult);
fclose($fp);
}

$kresult = $ktotal - $_POST[ktotal];
if ($_POST[ktotal] != ''){
$fp = fopen("k.txt", "w");
fwrite($fp, $kresult);
fclose($fp);
}

if(isset($_POST[reset])){
$fp = fopen("a.txt", "w");
fwrite($fp, $amountallowedA);
fclose($fp);
$fp = fopen("b.txt", "w");
fwrite($fp, $amountallowedB);
fclose($fp);
$fp = fopen("c.txt", "w");
fwrite($fp, $amountallowedC);
fclose($fp);
$fp = fopen("d.txt", "w");
fwrite($fp, $amountallowedD);
fclose($fp);
$fp = fopen("e.txt", "w");
fwrite($fp, $amountallowedE);
fclose($fp);
$fp = fopen("f.txt", "w");
fwrite($fp, $amountallowedF);
fclose($fp);
$fp = fopen("g.txt", "w");
fwrite($fp, $amountallowedG);
fclose($fp);
$fp = fopen("h.txt", "w");
fwrite($fp, $amountallowedH);
fclose($fp);
$fp = fopen("i.txt", "w");
fwrite($fp, $amountallowedI);
fclose($fp);
$fp = fopen("j.txt", "w");
fwrite($fp, $amountallowedJ);
fclose($fp);
$fp = fopen("k.txt", "w");
fwrite($fp, $amountallowedK);
fclose($fp);
header( 'refresh: 0; url=http://www.producthaus.com/$.php' );
}



?>
<head>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
-->
</style></head>

<body>

<table width="300" border="0">
<form name=form action='$.php' method='POST' enctype='multipart/form-data'>
<tr>
<td>
Cash<br><?php echo $amountallowedA; ?>$
</td>
<td>
<br><?php echo " Total:" . $aresult ; ?>$
</td>
<td>
<input name='atotal' type='text' class='text' size='5' id='atotal' > 
</td>
<td>
<input name='Submit' type='Submit' value='Ok'>
</td>
</tr>	

<tr>
<br>
<td>
Dining Out<br><?php echo $amountallowedB; ?>$
  </td>
<td>
<br><?php echo " Total:" . $bresult ; ?>$
  </td>
<td>
<input name='btotal' type='text' class='text' size='5' id='btotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>

<tr>
<br>
<td>
Drinks<br><?php echo $amountallowedC; ?>$
  </td>
<td>
<br><?php echo " Total:" . $cresult ; ?>$
  </td>
<td>
<input name='ctotal' type='text' class='text' size='5' id='ctotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>	


<tr>
<br>
<td>
Entertainment<br><?php echo $amountallowedD; ?>$
  </td>
<td>
<br><?php echo " Total:" . $dresult ; ?>$
  </td>
<td>
<input name='dtotal' type='text' class='text' size='5' id='dtotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>	

<tr>
<br>
<td>
Groceries<br><?php echo $amountallowedE; ?>$
  </td>
<td>
<br><?php echo " Total:" . $eresult ; ?>$
  </td>
<td>
<input name='etotal' type='text' class='text' size='5' id='etotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>

<tr>
<br>
<td>
Hobbies<br><?php echo $amountallowedF; ?>$
  </td>
<td>
<br><?php echo " Total:" . $fresult ; ?>$
  </td>
<td>
<input name='ftotal' type='text' class='text' size='5' id='ftotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>	

<tr>
<br>
<td>
Rent<br><?php echo $amountallowedG; ?>$
  </td>
<td>
<br><?php echo " Total:" . $gresult ; ?>$
  </td>
<td>
<input name='gtotal' type='text' class='text' size='5' id='gtotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>

<tr>
<br>
<td>
Savings<br><?php echo $amountallowedH; ?>$
  </td>
<td>
<br><?php echo " Total:" . $hresult ; ?>$
  </td>
<td>
<input name='htotal' type='text' class='text' size='5' id='htotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>

<tr>
<br>
<td>
Memberships<br><?php echo $amountallowedI; ?>$
  </td>
<td>
<br><?php echo " Total:" . $iresult ; ?>$
  </td>
<td>
<input name='itotal' type='text' class='text' size='5' id='itotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>

<tr>
<br>
<td>
Travel<br><?php echo $amountallowedJ; ?>$
  </td>
<td>
<br><?php echo " Total:" . $jresult ; ?>$
  </td>
<td>
<input name='jtotal' type='text' class='text' size='5' id='jtotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>

<tr>
<br>
<td>
Utilities<br><?php echo $amountallowedK; ?>$
  </td>
<td>
<br><?php echo " Total:" . $kresult ; ?>$
  </td>
<td>
<input name='ktotal' type='text' class='text' size='5' id='ktotal' > 
  </td>
<td>
<input name='Submit' type='Submit' value='Ok'>	
</td>
</tr>				

<?php // </form> SHOULD BE ALWAYS AFTER YOUR LAST AMOUNT! enjoy ^^ ?>
</form>
</table>
</body>

Link to comment
https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/
Share on other sites

I set up wamp, but still did not get any output of errors when I tested the php file in firefox and wamp. xampp, looked even more confusing to setup. :)

 

I'm still stuck trying to get any sort of errors to appear, is there anyone that could test the php file for me? The a.txt and other text files just contain a number a single number value each, like 200.

 

cheers,

nick

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.