0

I have a PHP file I created to display 100 inputs. However, this code displays as if it was an HTML file.

I have PHP installed, and VS code is set up to use it, but it still displays incorrectly.

<html>
  <head>
    <title>PHP Test</title>
  </head>
  <body>
    <?php
    for($i = 0; $i < 100; $i++) {
          $j = $i + 1;
        print "$j \r\n \r\n";
        print "<input id=".$i."a>";
        print "<input id=".$i."b>";
      print "<input id=".$i."c><br>";
    }
    ?>
    <br>
    </body>
</html>

"; print "<input>"; print "<input>
"; } ?>

This is what is displayed, but I would expect numbers from 1 - 100, and 400 input fields

  • 6
    How do you execute this file? If you are accessing file directly from the browser (something like file://path-to-your-file.php) then it won't work. Also make sure the file extension is `.php` – Vidhyut Pandya Jul 02 '19 at 13:44
  • @VidhyutPandya That's what was wrong, Thanks! – LukeS062022 Jul 02 '19 at 13:53
  • When ever you see php code instead of it being executed that means that php is not parsed (executed). When you are calling php script from browser and you see the code it means that web server (Apache, Nginx...) don't have PHP installed/configured well, of course, assuming that you are not opening the php file directly trough file system. – MilanG Jul 02 '19 at 14:01

1 Answers1

1
  1. Make sure file format is .php

  2. Make sure you open a page using your local server (I recommend to use OpenServer - https://ospanel.io/ )

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
IYHunko
  • 96
  • 5