Cristian Posted November 7, 2011 Share Posted November 7, 2011 Hello everyone. I am new here and I just started learning PHP; I apologize in advance for how stupid this question will seem to most of you I'm sure. I'm following a video guide and typing what the instructor says (I've checked it like 10 times) but for some reason he isn't getting an error and I am. I am just trying to do simple arithmetic. <html> <head> <title>Numbers - Christopher</title> </head> <body> <?php $var1 = 3; $var2 = 4; ?> Basic Math: <?php echo ((1 + 2 + $var1) * $var2) / 2 – 5; ?><br /> </body> </html> The answer that comes up on his screen is 7. On mine, it says this: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\christopher\numbers.php on line 11. I'm sure there is something stupid that I am missing. Anyone care to help out the newbie ? Quote Link to comment https://forums.phpfreaks.com/topic/250584-newbie-parse-error-syntax-error-unexpected-t_string-expecting-or/ Share on other sites More sharing options...
Gotharious Posted November 7, 2011 Share Posted November 7, 2011 You forgot the " in the echo use it like below Basic Math: <?php echo "((1 + 2 + $var1) * $var2) / 2 – 5"; ?><br /> Quote Link to comment https://forums.phpfreaks.com/topic/250584-newbie-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1285734 Share on other sites More sharing options...
Cristian Posted November 7, 2011 Author Share Posted November 7, 2011 I just tried that, and it still didn't give me the right result. It wrote out the math problem instead of solving it: Basic Math: ((1 + 2 + 3)) * 4) / 2 – 5 Quote Link to comment https://forums.phpfreaks.com/topic/250584-newbie-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1285736 Share on other sites More sharing options...
Gotharious Posted November 7, 2011 Share Posted November 7, 2011 That's because the echo doesn't calculate, it just posts it in the webpage in the browser Quote Link to comment https://forums.phpfreaks.com/topic/250584-newbie-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1285739 Share on other sites More sharing options...
Gotharious Posted November 7, 2011 Share Posted November 7, 2011 Maybe that would be better <html> <head> <title>Numbers - Christopher</title> </head> <body> <?php $var1 = 3; $var2 = 4; $var3 = ((1 + 2 + $var1) * $var2) / 2 - 5; ?> Basic Math: <?php echo $var3; ?><br /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/250584-newbie-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1285740 Share on other sites More sharing options...
Cristian Posted November 7, 2011 Author Share Posted November 7, 2011 Yes, that works now. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/250584-newbie-parse-error-syntax-error-unexpected-t_string-expecting-or/#findComment-1285741 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.