Question: I want to echo "success" on the same page the form is on if it uploaded correctly, but Im new to php so dont know how its done?

index.php

```
<form action="upload" method="POST">
<input name="field1" placeholder="First name" type="text" />
<input type="submit" name="submit" value="Submit">

```

upload.php

```
    $content = "".$_POST["field1"];
$fp = fopen("upload/test.txt","wb");
fwrite($fp,$content);
fclose($fp);

```

I also need it to redirect back to same page index.php

Answer: 
If you need to echo on the same page and you don't want to use ajax there are 2 possible solution.

a) Use a GET parameter on upload script, and thread this on the index.php (As @Brad also said at comment)

upload.php

```
$content = "".$_POST["field1"];
$fp = fopen("upload/test.txt","wb");
fwrite($fp,$content);
fclose($fp);
header('Location: /index.php?m=success');

```

index.php

```
//Check for message parameter
if (isset($_GET['m']{0}) && $_GET['m'] === 'success')
    echo 'Form uploaded successfully';

//Display the upload form
echo '<form action="upload" method="POST">' .
     '<input name="field1" placeholder="First name" type="text" />' .
     '<input type="submit" name="submit" value="Submit">';

```

b) Within the same script
index.php

```
//Check if form is submitted
if (isset($_POST['field1']))
{
    $content = "".$_POST["field1"];
    $fp = fopen("upload/test.txt","wb");
    fwrite($fp,$content);
    fclose($fp);

    //Do anything else
}

//Display form. Use index.php as the action, instead of upload
echo '<form action="/index.php" method="POST">' .
     '<input name="field1" placeholder="First name" type="text" />' .
     '<input type="submit" name="submit" value="Submit">';

```

**Update after comment**:

When you open a file with the fopen function, you define 2 arguments. The first argument is the filename, and the second argument is the flags.

You need the 'a' (append) flag, instead of 'w' (write): 

* 'a' Open for writing only; place the file pointer at the end of the
file. If the file does not exist, attempt to create it.
* 'w' Open for writing only; place the file pointer at the beginning
of the file and truncate the file to zero length. If the file does
not exist, attempt to create it.

Take a look [here](http://www.php.net/manual/en/function.fopen.php)
```
Try the following code
if (! move_uploaded_file ( $_FILES ['attachment'] ['tmp_name'], UPLOAD_DIR  )) {
    //handle if file not  uploaded

         header("Location:index.php?m=fail");
}else{

      header("Location:index.php?m=success");

}

```