user1644207
user1644207

Reputation: 1

PHP echo message before and after form submission, but need it after submit...see the code

<input name="Submit" type="submit" class="submitbtn" value="Submit" />
<?php if(isset( $_POST['Submit']) && $msg!='' ){?>
     <div class="erroroutput"><p><?php echo $msg; ?><br></p></div>
<?php } else{?>
        <div><center><h2>Thank you for submission</h2></center></div>
<?php }?>
</form>

I need to echo "Thank you for submission" after successful submission. But echoing before and after submission.

FYI: Form action on same page

THANKS GUYS FOR INPUT. IT"S RESOLVED

Upvotes: 0

Views: 5611

Answers (5)

i&#39;m PosSible
i&#39;m PosSible

Reputation: 1393

try this,

use two condition.

<?php if(isset( $_POST['Submit'])
      {
      if( $msg!='')
      {?>
        <div class="erroroutput"><p><?php echo $msg; ?><br></p></div>

    <?php } else{?>
    <div><center><h2>Thank you for submission</h2></center></div>
    <?php }
     }?>

Upvotes: 0

Lost Koder
Lost Koder

Reputation: 884

<input name="Submit" type="submit" class="submitbtn" value="Submit" />
<?php if(isset( $_POST['Submit']) && $msg!='' ){?>
     <div class="erroroutput"><p><?php echo $msg; ?><br></p></div>
<?php } else if(isset($_POST['Submit]){?>
        <div><center><h2>Thank you for submission</h2></center></div>
<?php }?>

Upvotes: 0

rebyte
rebyte

Reputation: 80

You have to check the submit quest in your else-if loop.

Replace your code with this:

<input name="Submit" type="submit" class="submitbtn" value="Submit" />
        <?php if(isset( $_POST['Submit']) && $msg!='' )
        {?>
            <div class="erroroutput"><p><?php echo $msg; ?><br></p></div>

        <?php } elseif (isset( $_POST['Submit'])) { ?>
        <div><center><h2>Thank you for submission</h2></center></div>
        <?php }?>
</form>

Upvotes: 0

duncan3dc
duncan3dc

Reputation: 248

You need 2 if statements, one to say "was the form submit?", and one to say "Is there an error message?"

<input name="Submit" type="submit" class="submitbtn" value="Submit" />
    <?php if(isset( $_POST['Submit']) {
        if($msg!='')
    {?>
        <div class="erroroutput"><p><?php echo $msg; ?><br></p></div>

    <?php } else{?>
    <div><center><h2>Thank you for submission</h2></center></div>
    <?php }
    }?>

Upvotes: 1

Ram Sharma
Ram Sharma

Reputation: 8809

change it like that

<input name="Submit" type="submit" class="submitbtn" value="Submit" />
    <?php if(isset( $_POST['Submit']) && $msg=='' )
    {?>
        <div><center><h2>Thank you for submission</h2></center></div>            
    <?php } else{?>
        <div class="erroroutput"><p><?php echo $msg; ?><br></p></div>        
    <?php }?>

Upvotes: 0

Related Questions