-2

Please keep in mind I am a beginner so please don't be too harsh.

I have spent hours researching ways to complete my 'mission'.

My mission is as follows... 1. I open my already created html web page 2. I click on the submit button 3. The submit button should execute PHP code. 4. The PHP code should write the current date and time to a .txt file located on my desktop without overwriting previous records.

My HTML page works perfectly fine. The submit button appears and when clicked it displays all the code from the .php file but doesn't actually run it. Even if it were to run the code I'm not sure if the code would work?

Could you please tell me why when I click on the button it displays the PHP code but doesn't run it. By the way, sorry I should have mentioned I was using Google Chrome. I can settle for IE if necessary but would prefer Chrome.

Here is the HTML file code

<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<form method="post" action="submit.php">
<input name="submit" type="submit" value="Connect" />
</form>

</body>  
</html>

Here is the PHP code

<?php
$file='phplog.txt';
$date= date('d-m-Y H:i:s');
file_put_contents($file, $date, FILE_APPEND);
?>

I checked the pre-created by me phplog.txt file and it was empty so... I don't know...

Please don't forget I would prefer this to work in Chrome :) Any help would be greatly appreciated!

Thanks :)

5
  • when clicked it displays all the code from the .php file but doesn't actually run it. - A: Install a webserver. Commented Dec 22, 2014 at 4:18
  • Are you on a Mac, Windows, or Linux machine? Commented Dec 22, 2014 at 4:19
  • 1
    possible duplicate of web browser not processing PHP code as PHP code and stackoverflow.com/questions/5121495/… Commented Dec 22, 2014 at 4:27
  • Sorry I should have mentioned @tlindell that I'm using Windows 8.1 Commented Dec 22, 2014 at 4:47
  • If you have not solved this issue yet. You will need to install a webserver such as WAMP or XAMPP. Another good one is Vagrant! Commented Apr 14, 2015 at 15:39

3 Answers 3

0

You need an environment like Apache to run PHP files. Check out Wamp Server to install Apache, MySQL, and PHP on your home computer.

Sign up to request clarification or add additional context in comments.

Comments

0

It's because you are not running your code into a webserver. You can install XAMPP https://www.apachefriends.org/index.html and then place your code into a folder, after that you can visit in your browser localhost/your_folder_name and it will work.

Comments

0

To run PHP files, you would require PHP to be present in your system which compiles and run a php script. Since you are using Windows, the easy and best thing for you to do would be install WAMP in your system, which would give you PHP, Apache and also MySQL. Here's the link where you can download WAMP, http://www.wampserver.com/en/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.