Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all,
I am new to PHP and web programming.
I have a very simple question,
I have following simple code:
****************************
<?php
if (isset($submit)) {
echo "If is executed";} else {
echo "Else is executed";
?>
<HTML>
<BODY>
<FORM enctype="multipart/form-data" method="post" action="upload.php">
Upload image
Select image: <INPUT name="file" type="file">
<INPUT type="submit" name= "submit" value="submit">
</FORM></BODY>
</HTML><?php
}
?>
***********************
A form appears on the screen and when I click on submit button I should be in "If statement" and the code line
echo "If is executed"; should be executed
but instead
echo "Else is executed"; statement is executing all the time.
What I am missing so that when I click on
submit button if statement should be executed.
thanks
regards
/rsasalm

There are a couple problems with what you have above. First of all you are trying to reference a locally defined variable called $submit. Since you never defined it, it doesn't exist. You need to reference the $submit variable that was posted to the page from the form, like this:
if (isset($_POST["submit"])) {
Also, you are echo'ing text to the page before the headers have been written, so the text might not even show up depending upon the browser you use.

Michael's explanation is right on...I'm just clarifying a couple of things.
If you have register_globals on, then what you have above should work ($_POST['submit'] is put into a variable named $submit). But in recent versions of PHP, it is off be default (mostly because of security considerations.)
Secondly, I think PHP will output the http headers before you echo anything. But Michael may be talking about the HTML 'header' tags (HTML, HEAD, TITLE, STYLE, etc.)
-SN

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |