-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 :)

  • *when clicked it displays all the code from the .php file but doesn't actually run it*. - **A:** Install a webserver. – Funk Forty Niner Dec 22 '14 at 04:18
  • Are you on a Mac, Windows, or Linux machine? – tylerlindell Dec 22 '14 at 04:19
  • 1
    possible duplicate of [web browser not processing PHP code as PHP code](http://stackoverflow.com/questions/6932913/web-browser-not-processing-php-code-as-php-code) and http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page – Mike M. Dec 22 '14 at 04:27
  • Sorry I should have mentioned @tlindell that I'm using Windows 8.1 – user4383958 Dec 22 '14 at 04: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! – tylerlindell Apr 14 '15 at 15:39

3 Answers3

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.

ShoeLace1291
  • 4,551
  • 12
  • 45
  • 81
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.

Javier Esquivel
  • 77
  • 1
  • 10
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/

Venkata Krishna
  • 1,768
  • 2
  • 14
  • 21