0

I have an index.html file

<section id = "AddFromDB">
        <form action="./phpFile.php" method="POST">

            <input type="text" id="inputUserID" placeholder="Lecturer ID" name="userID"></input>
            <button type="submit" id="submitButton">Submit</button>

        </form>


 </section>

and a phpFile.php file

<?php
    echo "Hello";
?>

and I am confused because when I run the php file even by itself (using its directory) in Firefox URL it doesn't show anything.

  • I checked online and I am not using the short version tags for php.
  • checked my php -v (It is installed, running latest php)
  • Tried using the URL system directory as well as a live sever extension from Visual Code

I do know that it is accessing the php file as I had other code in there but it was showing me the actual lines of the php file and not the echos. Nevertheless, it is not working for something this basic and I have no idea why.

EDIT: They both are in the same folder

EDIT (2): "Page Source" results

for index.html

<!DOCTYPE html>
<head>
    <meta charset="utf-8" />
    <title>To-Do List</title>
    <link rel="stylesheet" href="./reset.css" />
    <link rel="stylesheet" href="./style.css" />
    <script type="text/javascript" src="./javascript.js"></script>
</head>

<body>
    <header>
        <h1>
            To-Do List
        </h1>
    </header>

    <section id="saveTaskSection">
        <div id="TAdiv">
            <textarea id="toDoListTA" rows="8" cols="80"></textarea>
        </div>
        <button id="saveTaskButton" type="button" onclick="saveTask()">
            Save Task
        </button>

    </section>

    <section id = "AddFromDB">
        <form action="./phpFile.php" method="POST">

            <input type="text" id="inputUserID" placeholder="Lecturer ID" name="userID"></input>
            <button type="submit" id="submitButton">Submit</button>

        </form>


    </section>

    

    <section id="showTasksSection"></section>
</body>

for phpFile.php

<?php
    echo "Hello";
?>

I have been notified that php requires a server in order to run. My apologize. Thank you for the information.

FOR ANY FUTURE READERS, THE COMMENTS BELOW ARE EXTREMELY HELPFUL. ALSO IF YOU ARE ON VISUAL STUDIO CODE OR ON ANY OTHER CODE EDITOR, CHECK THE EXTENSIONS/PLUGINS FOR YOUR CODE EDITOR AS THEY MIGHT HAVE ONE FOR PHP SERVER, FOR VISUAL CODE THERE IS ONE, IT MAKES ITS OWN localhost(port number) AND INTEGRATES SMOOTHLY WITH YOUR INDEX.HTML AND ANY CHANGES

Arneev
  • 39
  • 8
  • Use View Source, what do you see there? – Barmar Jul 24 '20 at 20:52
  • I updated with the "Page Source". – Arneev Jul 24 '20 at 21:00
  • 2
    Can you explain your local server setup more? What is the URL you were trying to access your php file at (or index.html for that matter)? Was it something like `http://localhost/phpFile.php`, or were you trying to access it directly via filepath like `C:/website/index.html` (windows) or `file:///Users/example.user/website/index.html` (mac)? Or are you running a local webserver like XAMPP or MAMP? – WOUNDEDStevenJones Jul 24 '20 at 21:01
  • 1
    Just because PHP runs via the command line doesn't mean it will run a web page. You need a web server first, and then it needs to be configured to use PHP. – j08691 Jul 24 '20 at 21:02
  • What is your webserver? If you are using windows try installing XAMPP as it is simple and straightforward. – Undry Jul 24 '20 at 21:04
  • it seems like your PHP Code is not interpreted, you need some kind of server (Apache oder Nginx) – mrfr34k Jul 24 '20 at 21:04
  • Since PHP 5.4, PHP comes with a [buil-in server](https://www.php.net/manual/en/features.commandline.webserver.php). So you can go to your folder, run `php -S localhost:8080` and view [http://localhost:8080/phpFile.php](http://localhost:8080/phpFile.php) in your browser. But beware, this feature should only be use for development and other limited uses. – Hepson Jul 24 '20 at 22:37

0 Answers0