GoodVibe Posted March 28, 2012 Share Posted March 28, 2012 Ok. So I.m trying to learn the language. I have this program: <?php require_once("fillarray.inc"); ?> <html> <head> <title>PHP Class Lesson 2 - AJ</title> </head> <body> <h1>The Circumference of a Circle</h1> <br> <table border="1"> <thead> <tr> Circle Number:</tr> <tr> Diamater</tr> <tr> Circumference</tr> <tr> radius</tr> <tr> Area</tr> </thead> <?php foreach($arr as $diameter){ echo ("<td>"); echo("<tr align=\"center\"> 1 </tr>"); echo ("<tr> $diamater </tr>"); $circumference = $diameter * M_PI; echo ("<tr> $circumference </tr>"); $radius = $diameter/2; echo ("<tr> $radius </tr>"); $area = pow($radius,2)*M_PI; echo ("<tr> $area </tr>"); echo ("</td>"); } ?> </table> </body> </html> and in fillarray.inc I have: $totalnum = rand(0,25); $arr = array(); for($i=0;i<$totalnum;i++){ $arr[$i] = rand(1,100); } But when I run it, this is the display i get: $totalnum = rand(0,25); $arr = array(); for($i=0;i<$totalnum;i++){ $arr[$i] = rand(1,100); } The Circumference of a Circle Circle Number: Diamater Circumference radius Area Any help on whats going on? Quote Link to comment https://forums.phpfreaks.com/topic/259886-problem-with-include/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2012 Share Posted March 28, 2012 The php code in the file you are including must be valid php code, with any opening and closing php tags (you can include anything, like HTML, and php must be told where the php code starts and ends in every file.) Also, use .php for the extension of the file. It does not matter in this case, but if you start putting database connection credentials in an included file, if the file extension is not .php, someone can browse to the file and get the raw database connection credentials. Quote Link to comment https://forums.phpfreaks.com/topic/259886-problem-with-include/#findComment-1332016 Share on other sites More sharing options...
GoodVibe Posted March 28, 2012 Author Share Posted March 28, 2012 when I add the php tags, i get this error: Parse error: syntax error, unexpected T_INC, expecting ')' in /www/99k.org/t/h/e/thegoodvibe/htdocs/Class/Lesson3/fillarray.inc on line 4 if I look at my file, line 4 is: $arr = array(); and i cant figure out why it tells me that Quote Link to comment https://forums.phpfreaks.com/topic/259886-problem-with-include/#findComment-1332019 Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2012 Share Posted March 28, 2012 Line 4 is the for() statement. You are missing the $ in front of one of the i variable names. Quote Link to comment https://forums.phpfreaks.com/topic/259886-problem-with-include/#findComment-1332026 Share on other sites More sharing options...
GoodVibe Posted March 28, 2012 Author Share Posted March 28, 2012 Thank you, I will now kindly take the solution and facepalm myself. Quote Link to comment https://forums.phpfreaks.com/topic/259886-problem-with-include/#findComment-1332029 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.