7

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!

Eric
  • 640
  • 12
  • 32
  • What is the extension of the file? What is the server you are running this on? – Kieran Andrews Mar 14 '12 at 21:58
  • Does your file name end in '.php'? ;) – iambriansreed Mar 14 '12 at 21:59
  • so many things wrong with this.. for starters though, are you sure php is installed on your server? – Carrie Kendall Mar 14 '12 at 21:59
  • 1
    This may just indicate that PHP isn't being interpreted at all. Try looking for hints in [previous questions like this one](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page), say. What web server are you using? Do you know how PHP is configured? Are you saving your files as "whatever.php"? What URL are you going to to display the pages? Do you see *all* the PHP if you "view source" in your browser? – Matt Gibson Mar 14 '12 at 22:00
  • The code provided works correctly when tested. Are you sure PHP is working properly? – Rick Kuipers Mar 14 '12 at 22:01
  • The php code seems to be fine, but your html might need some improvement... You only close the form, don't open. Input and br should be self-closing tags like: and
    – Scuba Kay Mar 14 '12 at 22:08
  • Incidentally, PHP and HTML have both come a long way since 2005. You might be a great deal better off finding more recent tutorials. – Matt Gibson Mar 14 '12 at 22:11

1 Answers1

4

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

Dudeist
  • 363
  • 1
  • 4
  • 13