Jump to content

Problem using a php variable in an html if..else


Go to solution Solved by Barand,

Recommended Posts

I need to use a php variable in an if.. else clause outside of the block of php code and can't get it working. The existing code block is below. All help is appreciated.

$chk is the variable from the php block and is numeric.

<?php if($chk == 0) { 
  <div id='showMe'>
   <div class="container">
      <div class="row" style="color:red; padding-top:6rem; text-align:center;">
         <h1>Database Update Failed</h1>
      </div>
   </div>
 </div> }
 
else  { 
<div id='showMe'>
  <div class="container">
      <div class="row" style="padding-top:6rem; text-align:center;" >
        <h1><center>Database Update Successful</center></h1>
      </div>
  </div>
endif
</div>  

 </div>  
   </body>
</html>

Thanks much.

Curly braces and endif don't play nice together. Use one syntax or the other.

<?php if($chk == 0) { ?>

  <div id='showMe'>
   <div class="container">
      <div class="row" style="color:red; padding-top:6rem; text-align:center;">
         <h1>Database Update Failed</h1>
      </div>
   </div>
 </div> 
 
<?php } 
      else  
      { ?>
 
    <div id='showMe'>
      <div class="container">
          <div class="row" style="padding-top:6rem; text-align:center;" >
            <h1><center>Database Update Successful</center></h1>
          </div>
      </div>

    </div>  

<?php }  ?> 

</body>
</html>

Thanks, Barand. It's working better but now I get both results from the if clause when $chk =1.

<?php if($chk == 0)  ?>
  <div id='showMe'>
   <div class="container">
      <div class="row" style="color:red; padding-top:6rem; text-align:center;">
         <h1>Database Update Failed</h1>
      </div>
   </div>
 </div>  
else 
  <div id='showMe'>
    <div class="container">
      <div class="row" style="color:black; padding-top:6rem; text-align:center;" >
        <h1>Database Update Successful</h1>
      </div>
    </div>
  </div>  

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.