Search code examples
phphtmltextvisible

PHP code is visible on website


I am in the process of learning PHP and I ran into a snag, and I feel it is because the video tutorials I am watching are from 2005 and some of the API's haven't transferred over to current standards. Long story short one of the "challenges" is to create a quiz and no matter what I do the PHP code leaks over and is printed 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 outputs everything that it is supposed to but at the very end it also prints out:" "; $q1answer = "d"; ?>"

What's confusing to me is why it prints anything at all, for starters, because I am just instantiating a variable and no where am I printing it. Second, why is it displaying the PHP code as text output?

Also, for the record I am using a switch statement which prefixes the variable $question1 with the opening "form" brackets so I don't think it is because I am including it on the variable. Any thoughts would be greatly appreciated!


Solution

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