PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
swudev
Forum Newbie
Posts: 2 Joined: Thu Jul 30, 2009 12:41 pm
Post
by swudev » Thu Jul 30, 2009 12:46 pm
I am having problems adding four string values that I'm reading from a text file.
It pulls the values successfully.
And I can output those.
But I keep getting an error performing the addition.
Thanks in advance.
Code: Select all
<?php
$myFile = "count01.txt";
$fy = fopen($myFile, 'r');
$Data01 = fread($fy, filesize($myFile));
fclose($fy);
$myFile = "count02.txt";
$fn = fopen($myFile, 'r');
$Data02 = fread($fn, filesize($myFile));
fclose($fn);
$myFile = "count03.txt";
$fn = fopen($myFile, 'r');
$Data03 = fread($fn, filesize($myFile));
fclose($fn);
$myFile = "count04.txt";
$fn = fopen($myFile, 'r');
$Data04 = fread($fn, filesize($myFile));
fclose($fn);
$DataTotal = (int)$Data01 + (int) $Data02 + (int) $Data03 + (int) $Data04
echo"
1: $Data01<br>
2: $Data02 <br>
3: $Data03 <br>
4: $Data04
;
?>
Thanks again,
Scott
straightman
Forum Commoner
Posts: 48 Joined: Sun Apr 19, 2009 5:20 am
Post
by straightman » Thu Jul 30, 2009 12:51 pm
are you closing your double quotes allright?
==========================================================
swudev wrote: I am having problems adding four string values that I'm reading from a text file.
It pulls the values successfully.
And I can output those.
But I keep getting an error performing the addition.
Thanks in advance.
Code: Select all
<?php
$myFile = "count01.txt";
$fy = fopen($myFile, 'r');
$Data01 = fread($fy, filesize($myFile));
fclose($fy);
$myFile = "count02.txt";
$fn = fopen($myFile, 'r');
$Data02 = fread($fn, filesize($myFile));
fclose($fn);
$myFile = "count03.txt";
$fn = fopen($myFile, 'r');
$Data03 = fread($fn, filesize($myFile));
fclose($fn);
$myFile = "count04.txt";
$fn = fopen($myFile, 'r');
$Data04 = fread($fn, filesize($myFile));
fclose($fn);
$DataTotal = (int)$Data01 + (int) $Data02 + (int) $Data03 + (int) $Data04
echo"
1: $Data01<br>
2: $Data02 <br>
3: $Data03 <br>
4: $Data04
;
?>
Thanks again,
Scott
swudev
Forum Newbie
Posts: 2 Joined: Thu Jul 30, 2009 12:41 pm
Post
by swudev » Thu Jul 30, 2009 1:51 pm
Thanks for the reply.
Yes, my quotes do close, I have some additional code that I clipped this out of.
It functions fine until I add the line performing the addition.
Any thoughts?
ronnietherocket
Forum Newbie
Posts: 5 Joined: Mon Jul 20, 2009 11:38 am
Post
by ronnietherocket » Thu Jul 30, 2009 1:59 pm
have you tried echo on each of the four things that you read to make sure they are all numbers?
straightman
Forum Commoner
Posts: 48 Joined: Sun Apr 19, 2009 5:20 am
Post
by straightman » Thu Jul 30, 2009 2:04 pm
I am not seeing that you have the ; statement finishing your equation of the addition.
=======================================================================
straightman wrote: are you closing your double quotes allright?
==========================================================
swudev wrote: I am having problems adding four string values that I'm reading from a text file.
It pulls the values successfully.
And I can output those.
But I keep getting an error performing the addition.
Thanks in advance.
Code: Select all
<?php
$myFile = "count01.txt";
$fy = fopen($myFile, 'r');
$Data01 = fread($fy, filesize($myFile));
fclose($fy);
$myFile = "count02.txt";
$fn = fopen($myFile, 'r');
$Data02 = fread($fn, filesize($myFile));
fclose($fn);
$myFile = "count03.txt";
$fn = fopen($myFile, 'r');
$Data03 = fread($fn, filesize($myFile));
fclose($fn);
$myFile = "count04.txt";
$fn = fopen($myFile, 'r');
$Data04 = fread($fn, filesize($myFile));
fclose($fn);
$DataTotal = (int)$Data01 + (int) $Data02 + (int) $Data03 + (int) $Data04
echo"
1: $Data01<br>
2: $Data02 <br>
3: $Data03 <br>
4: $Data04
;
?>
Thanks again,
Scott
straightman
Forum Commoner
Posts: 48 Joined: Sun Apr 19, 2009 5:20 am
Post
by straightman » Thu Jul 30, 2009 2:05 pm
I am not seeing that you have the ; statement finishing your equation of the addition.
===================================================================================
$DataTotal = (int)$Data01 + (int) $Data02 + (int) $Data03 + (int) $Data04
echo"
1: $Data01<br>
2: $Data02 <br>
3: $Data03 <br>
4: $Data04
;
?>
Thanks again,
Scott[/quote][/quote][/quote]
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Thu Jul 30, 2009 2:12 pm
Turn on error reporting, is the simple answer.
straightman
Forum Commoner
Posts: 48 Joined: Sun Apr 19, 2009 5:20 am
Post
by straightman » Thu Jul 30, 2009 2:18 pm
yes Jackpf, but dont you think that it is because he has left the ; out? i dont see it in his equation of addition
===================================================================================
jackpf wrote: Turn on error reporting, is the simple answer.
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Thu Jul 30, 2009 2:26 pm
I'm pretty sure it is because he's missing a semi-colon. It's probably also because he's missing a quotation mark.
But, if he turns on error reporting, it'll show him that he has errors on those particular lines.
But yes, you are right about what's causing the errors
I'm just trying to show how he should go about debugging these errors now, and in the future.