foxclone Posted January 21, 2022 Share Posted January 21, 2022 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 21, 2022 Share Posted January 21, 2022 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> Quote Link to comment Share on other sites More sharing options...
foxclone Posted January 22, 2022 Author Share Posted January 22, 2022 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> Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted January 22, 2022 Solution Share Posted January 22, 2022 Look again at my code. Quote Link to comment Share on other sites More sharing options...
foxclone Posted January 22, 2022 Author Share Posted January 22, 2022 Thanks again. I missed the php code surrounding the else. It's all working correctly now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.