Background info: just started learning PHP this weekend; the only language I have studied is C# and am somewhat comfortable with it. My OS is Win7. I downloaded XAMPP and am following an online tutorial and things are going well. Until I ran into the following that I’ve turned upside down and inside out and don’t understand why it won’t work.
Here’s the problem: I have a simple form (“upload”) to upload a file; when the “action” references a different php file (“upload2”) all works as intended. But the moment I take the same code, put it into a single file (“upload3”) the whole thing acts like it’s not posting. The code below are the 3 files referenced here; and the last piece of code is code I wrote from the tutorial, it works as intended, and is the process I attempted to duplicate (so frustrating to write something that works, then something that doesn’t…and you can’t tell the difference between the two; so sad). Thanks in advance for your advice and help.
This is the simple form, “upload”:
[php]
This is the server-side response, super trimmed down for testing, “upload2”:
[php]
[/php]
And those work as one would imagine. But this one, “upload3” doesn’t:
[php]
If I change upload3’s action to reference upload2.php everything works fine. It’s as if I can’t get the file to recognize itself. What confounds me, and kept me going on the problem for a couple of hours is previously in the tutorial I followed this method and it worked…and no amount of reckoning by me can figure out the difference:
[php]
PHP Forms <?php if(!$_POST) { $filename=$_SERVER["PHP_SELF"]; echo '<form method="post" action="'.$filename.'">
<p><label for="firstname">Type your first name here: </label><input type="text" name="firstname" id="firstname" /></p>
<p><label for="surname">Type your surname here: </label><input type="text" name="surname" id="surname" /></p>
<p><label for="dob">Your date of birth (dd/mm/yyyy): </label><input type="text" name="dob" id="dob" /></p>
<input type="submit" name="submit">
</form>';
} else {
$firstname=$_POST["firstname"];
$surname=$_POST["surname"];
$dob=$_POST["dob"];
echo '<div id="green">';
echo "Hello $firstname $surname I believe you were born $dob";
echo '</div>';
echo '<div style="background-color: yellow;">';
echo '<p>Using $_POST: </p>';
echo '<pre>';
print_r($_POST);
echo '</pre>';
echo '</div>';
}
?>
</body>
[/php]
Hopefully that wasn’t too much information. What am I missing? I look to be following the working model I created early in the tutorial but…yeah… Once again, tremendous thank you to anyone that responds.