[Webinar] Streamline your web hosting managementRegister Today

  • Status: Open
  • Priority: Low
  • Security: Public
  • Views: 21
  • Last Modified:

Display and hide div based on if statement

Hi Guys. I'm having a serious problem that is holding me back. I have a file which is a user dashboard and this file gets data from another php script file which is called by a user login screen when a user clicks login. The file verify the credentials then if correct that its start to pull some data from the database. The problem is that now there are some users who don't complete their registration process which some stop where they need to make their payments so their accounts are kept with a status of pending which indicate that the user has not pay the registration fee. Now I am able to read the status from the database and assign it to the session so that I will work with on the dashboard, this controls which tells if the complete your registration button should be shown or not of which in this case because the status is pending the dashboard should show this button. My problem is showing or hiding it as this should be hidden when a user has paid his/her registration fee because this update the database with Active status.

I've tried this:
<div if($_SESSION['iiio'] == "pending"){echo " style='display: block';"};><a href="https://www.paymentgateway.com" ><button align="right" id="completeReg" name="completeReg"  class="btn btn-danger my-cart-btn my-cart-b" >Complete RegistrationComplete Registration</button></a></div>

Open in new window

But the above will just do what the `display:xxxx` has if it has `none` it won't display the block even if the condition is not met for this where it should display because the condition is no met and if I had `block` it will keep displaying the even if the condition is not met. I've also tried adding the `else` but still.

I've also tried JavaScript:
<script type="text/javascript">

     var xadminFee = '<%= Session["iiio"] %>';
     if(xadminFee == "pending"){
         document.getElementById("completeReg").style.display = "block"; // This is for displaying the complete registration process.
        document.getElementById("completeReg").style.display = "none";


Open in new window

And still this seems as if its doesn't work at all because the div will always be shown even if I put `none`n but still.

Remember the session is from a php file which contains the exact status from the database.

Anyone who can help me solve this problem.
Mlungisi Ndlela
Mlungisi Ndlela
1 Comment
Chris StanyonCommented:
Just wrap your entire button inside a PHP if statement:

<?php if($_SESSION['iiio'] == "pending"): ?>

    <a href="https://www.paymentgateway.com">
        <button align="right" id="completeReg" name="completeReg" class="btn btn-danger my-cart-btn my-cart-b" >Complete Registration</button>

<?php endif; ?>

Open in new window

Now that block will only be rendered if iiio is 'pending'

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now