Jump to content


Photo

Error with variables


  • Please log in to reply
4 replies to this topic

#1 Hellusius

Hellusius
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 02 September 2006 - 10:08 AM

I am trying to sum two variables, but it gives me the following error

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/www/warnicro.awardspace.com/stats.php on line 3

The php code is

<? 
echo "<font color=\"#EFDFA0\">Statistics<br />;
$count = file_get_contents("count.txt"); 
$count2 = file_get_contents("count2.txt"); 
echo "<font color=\"#EFDFA0\">Homepage views: ".trim($count); 
echo "<font color=\"#EFDFA0\">Total page view: ".trim($count) + ($count2);
?> 

Anyone see what I am doing wrong?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 10:12 AM

You forgot to close your first echo statement:
echo "<font color=\"#EFDFA0\">Statistics<br />";

#3 Hellusius

Hellusius
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 02 September 2006 - 10:17 AM

thank you.
with that solved I bumped into another problem which is I want them to sum up but instead the are placed behind one another so the answer is 15315 while it should be 168

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 September 2006 - 10:24 AM

Use this:
echo "<font color=\"#EFDFA0\">Statistics<br />";
$count = file_get_contents("count.txt");
$count2 = file_get_contents("count2.txt");

echo "<font color=\"#EFDFA0\">Homepage views: " . trim($count) . "</font><br />";
echo "<font color=\"#EFDFA0\">Total page view: " . (trim($count) + $count2);


#5 Hellusius

Hellusius
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 02 September 2006 - 12:00 PM

That works, Thank you very very much :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users