PHP code is displayed on the website

I am involved in the process of learning PHP, and I ran into a problem, and I feel that the video tutorials that I have been watching are from 2005, and some of the APIs have not moved to current standards. In short, one of the “challenges” is to create a quiz and no matter what I do, the PHP code leaks and prints along with the HTML.

<html> <head><title>Chapter #4 Challenge</title></head> <body> <h2> Chapter #4 Quiz</h2> <?php $question1 = "<b>Question #1: What does the operator == mean?</b><br> A) <input type=radio name='q1' value='a'>Equals<br> B) <input type=radio name='q1' value='b'>Not Equal<br> C) <input type=radio name='q1' value='c'>True<br> D) <input type=radio name='q1' value='d'>Assignment<br> <input type=submit value='Submit'> </form><br>"; $q1answer = "d"; ?> </body> </html> 

The code displays everything that is supposed to, but at the very end it also prints: "; $ q1answer =" d ";?>"

What confuses me, why does it print anything at all, for starters, because I just create a variable and I won’t print it. Secondly, why does it display PHP code as text output?

In addition, for the record, I use the switch statement, which is the prefix of the variable $ question1 with open form brackets, so I don’t think that this is because I include it in the variable. Any thoughts would be greatly appreciated!

+7
source share
1 answer

I am sure your file is not with the * .php or / extension, and your server is not running php.

+3
source

All Articles