Question: I have a file with a simple html-form with button and a php-script. This script should count, how many times the button was clicked. Here's the code:

```
<? php
 if( isset($_POST['clickCount']) ) { 
incrementClickCount();
 }

function getClickCount()
{
    return (int)file_get_contents("index.html");
 }

 function incrementClickCount()
 {
$count = getClickCount() + 1;
file_put_contents("index.html", $count);
}
?>

<html>
<head>
<title>PHP</title>
</head>
<body>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" value="click" name="clickCount">
 </form>
 <div>Click Count: <?php echo getClickCount(); ?></div>

 </body>
 </html>

```

The problem is when I click on the button it gives me an error:

```
 file:///C:/Web_8/%3C?php%20$_SERVER[%27PHP_SELF%27];%20?%3E

```

I do't really work with php, so I don't know, what part of my code is wrong. Hope for someone to tell me, how to make it work.

Answer: 
First create a data.txt in the directory .. then run the script ..

**Advice : The name of this kind feature is hitcounter .. You Should use database to do this**

```
<?php

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

        $data = (int)file_get_contents("data.txt");
        $data = $data + 1;
        file_put_contents("data.txt", $data);
    }

?>

<html>
<head>
<title>PHP</title>
</head>
<body>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="count" value="<?php echo $data;?>">
<input type="submit" value="click" name="clickCount">

 </form>
 <div>

 </body>
 </html>

```

If You are just playing with PHP then You can try this too

```
<?php

    if (isset($_POST['clickCount'])) {
        # code...
        $data = $_POST['count'];
        $data = $data + 1;
    }

?>

<html>
<head>
<title>PHP</title>
</head>
<body>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="count" value="<?php echo $data;?>">
<input type="submit" value="click" name="clickCount">

 </form>
 <div>

 </body>
 </html>

```
I don't really understand what you want to do in your script, but PHP files have to be served by a webserver. You can not just open PHP files in a browser.