0

Reply to Quentin: EDIT TO QUESTION:

Hi Quentin. I'm new to this site, as of today, so pls forgive me if I'm handling this process incorrectly. As I didn't find an answer relative to my questions in the Search. In the answer I did find, the user was informed that they did not initialize their variable, so php would not print the output. Another answer listed some checks to see if PHP running and configured properly, and I did that and it appears to be. Also another said not to use short tags, and I'm not, so I'm kinda at a loss, and since I'm using my host, and not doing this locally, the other suggestions didn't apply.

Also, in my case, I did however, initialize my variables first, and use tags, so I thought there might be a different reason as to why it's outputting the code instead of executing it. Or does that not make a difference?

Thank you Quentin ...


I am taking a PHP class, and I have to write a "guessing game" program. Let me say, I'm not looking for coding support, as I prefer to figure that out on my own and seek help only if I feel I need it.

But what I am asking is: I have created my php files in the File Manager on my host server. I've run the code through a PHP code checker, and there are no errors, and I checked the error_log, and there are none there either. But what is happening when I run the source code -- which you can see here -- (http://www.jquelines.com/PHP/Assignments/Week_4/guessing_game.html) is that the output is showing a portion of my php code instead of executing it.

So my questions are:

1) Why is it printing the code instead of processing it?

2) Might this have to do with a setting in a file somewhere on my host server? Which I sought ... but honestly had no idea what I was looking for. And oddly enough, it was to no avail when I tried to get assistance from them.

Here is my code snippet:

/*<?php 

      if (isset ($_POST['submitUsernum'])) {

        //Get generated a random number
        $mynum = $_POST[‘mynum’];

        //Retrieve user input
        $usernum = $_POST[‘usernum’];

        //Track number of chances
        $chances = $chances + 1; 

        if ($usernum == $mynum) {
          if ($chances == 1) {
              echo 'WOW, that was awesome! You guessed my number on your first try.';  
              echo '  I was thinking number: ' . $mynum . ' And you guessed number: ' .  $usernum;
          } else {
            echo 'You got it!  Good guess!';
            echo 'Enter a new number to try again!';

            //Allow the user to play agian
            $mynum = rand(1,100);                      
           }        

        } elseif ($usernum > $mynum) {
          echo 'Sorry!  Your guess was too high.  Try again!';  
        } else {          
          echo 'Sorry!  Your guess was too low.  Try again!';  
        }
      } else {
        $mynum = rand(1,100);
        $chances = 0;
        } 
    ?>
*/

Much thanks in advance ...

teddyeloise

0 Answers0