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!
You've written your first PHP program, but when you go to run it, all you see in your browser is the code—the program doesn't actually run. When this happens, the most common cause is that you are trying to run PHP somewhere that doesn't support PHP.
PHP is a server-side programming language, meaning it is executed at the web server before the website is sent to the end-user. This is why you can't see the PHP code when you view the source code.
Use the isset() function upon the superglobal $_COOKIE variable to check if a cookie is set.
I am sure, your file is not with *.php extension or/and your server is not php running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With