开发者

show the form only if submit is not set

开发者 https://www.devze.com 2023-03-26 22:44 出处:网络
I am trying to show the form only if submit is not set, and if set then upload file and show link to the same page so that a new file could be uploaded again.

I am trying to show the form only if submit is not set, and if set then upload file and show link to the same page so that a new file could be uploaded again.

It shows the form even after I click on the submit button. I have not added an upload script now.

<body>
<?php 
    if (isset($_POST['submit']))
    {
        $output_form == 'no';
        echo 'hiiiii';
    }
    else {
        $output_form = 'yes';
    }
    if($output_form = 'yes')
    {
?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="file" name="uploadpic"  />
    <input type="submit" value="Upload" n开发者_JS百科ame="submit" />
</form>

<?php
    }
?>
</body>


  • $output_form == 'no'; should be $output_form = 'no';
  • if ($output_form = 'yes') should be if ($output_form == 'yes')

= is assignment, whereas == is a comparison.

Also, your form will use GET because you did not ask it to use POST with method="POST".


You're missing your method on the form element.

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

You can also use print_r($_POST) to see what's in the array.

Here's an example of it working, as well as the code.

http://www.wecodesign.com/demos/stackoverflow-7018639.php


if($output_form = 'yes')

should be

if($output_form == 'yes')

The way you have it now, you're assigning a value.


It should be

if($output_form == 'yes')


You doing assignment, use comparison:

if($output_form == 'yes')


Ensure that you're actually SETTING the no value as well:

 $output_form == 'no';

Should be

$output_form = 'no';
0

精彩评论

暂无评论...
验证码 换一张
取 消