My PHP While-Loop Factorial code is not working?


#1


People are telling me it is working fine, but I'm saving it under hypertext and then going to it and this error pops up. I don't understand how I can make it work for me.


Parse error: syntax error, unexpected ' echo' (T_STRING) on line 20


<!DOCTYPE html>
<html>
<body>
<style>
body {
    background-color: orange;
}
</style>
<h1>Factorial PHP</h1>

<?php
$userInput = 9;
$factorial = 1;
$num_1 = 1;
$num_2 = 1;
echo "The first value is " .$num_1. "<br>";
echo "The second value is " .$num_2. "<br>";
do {	
	$factorial = $factorial * $userInput;
   echo "<br>The next value is: " .$userInput;
    $userInput--;
} while ($userInput >= 1);  
?>

</body>
</html>


#2

Can you give the exact link of this sum ?


#3

http://web-students.armstrong.edu/~la3523/PHPwhileFact.html


#4

You have to find factorial ?right!
The link is forbidden for me! Can you explain what exactly your question was?
To find the factorial ?
This program prints this..


#5

I don't know why it won't allow you to view the link. Yes that is exactly what should be coming out of my code.

My code comes out with the right thing, but once I save it under hypertext and upload it to my server it comes out with an error instead of the factorial formula.


#6

So its your school/college homework!
You can ask your buddies ,if their code gets submitted or not?
It may be your school's server!


#7

Yes except I already did this code at school and it was correct. But now at home I went to add it to our server and it is no longer working. They are all working on theirs too. The biggest problem is that I have to convert other codes and if I can't get this one to work on the server I won't be able to get the others to work on it either and I won't be able to make sure they are all correct.


#8

Hey, there are many versions of php.
Maybe your code is not supported by your school's server!
Like Let me show you this..
version 7.0 of php

version 5.6 of php

Most probably your school server php version is outdated!

Ps : try to ask your buddies! you'll have some help from them!


#9

I put the exact same thing you put in on that site with the 7.0 version and this came up for me, "
FATAL ERROR syntax error, unexpected ' echo' (T_STRING) on line number 10".

I have no idea why my computer comes out with different things!

That could possibly be the reason, but I have a Fibonacci php code on the server that works fine!


#10

It simply means that Your school's code checking server supports older version of php!


#11

This link may help but its too technical at first sight!

Keep refreshing the page while submission! I will work!


#12

Oh my goodness that is a lot! I will try my best to figure it out. Thank you!


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.