hausnfranz Posted October 14, 2008 Share Posted October 14, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2008 Share Posted October 14, 2008 Add the following two lines immediately after your first opening <?php tag to get php to help you - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/#findComment-665589 Share on other sites More sharing options...
hausnfranz Posted October 14, 2008 Author Share Posted October 14, 2008 Where might the errors appear? I tried viewing in Expression Web and Dreamweaver. I can test the PHP in Firefox, etc, but I get no error output? Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/#findComment-665614 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 PHP is server side, in order to view the file on your local machine, you must have php installed. You could upload it to your webserver. Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/#findComment-665621 Share on other sites More sharing options...
Shaun Posted October 14, 2008 Share Posted October 14, 2008 If you dont have a web server to run it from, you can simple use http://www.wampserver.com/ . I use it for all my dev work, it is very simple and easy. No configuration needed Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/#findComment-665625 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 no use xampp! Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/#findComment-665650 Share on other sites More sharing options...
hausnfranz Posted October 15, 2008 Author Share Posted October 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128434-php-file-not-reading-external-files/#findComment-666312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.