I am trying to pass variables buy echoing new forms after using header("Location: location.php"). So when it is redirected, it outputs the form in the redirectred php file.
<?php
header("Location: location");
echo "<form><input type = 'submit' value ='try again' > </form>";
//expected output:the form outputs in the same files
?>
Using header("Location:page")
immediately exits your script and redirects the user to that page. However, I have successfully accomplished something very similar (to what I think you want) by scripting a Website Registration API.
In total, I wrote 3 critical scripts, plus the original form page, in/out functions, and an assortment of data storage modules to create a seamless process. Your needs might not be as complicated as mine, but I found this to be much more involved than a simple 'validation check'.
Basic outline:
Try to solve your problem by thinking about each step of the process and breaking it down into bite-size pieces. (first you have to see the input, then you have to check the input, etc.)
After the header("Location:url");
no other command will be executed but you can used document.getElementById("myForm").submit();
<form id="form" action="/url"><input type = 'submit' value ='try again' > </form>";
//expected output:the form outputs in the same files
<script>
document.getElementById("form").submit();
</script>
or used curl