Rizzzler
Rizzzler

Reputation: 193

Not run if value is not set in database

I have this code on my website. Basically it hides code on the site if you are not logged in.

In my database I have a table called "users" where userdata is stored. I have added a new column to the table called "subdomain" where the default value is 0 and 1 when it's active.

Except only being run when a user is logged in, I also only want the code to only be run if the column "subdomain" in the table "users" for the current logged in is set to 1. If it's not set to 1 the code should not be run and keep being hidden, even if the user is logged in.

How can this be done ?

Shows the username of the logged in user --> <?php echo $Auth->username; ?>

Show the user ID of the logged in user --> <?php echo $Auth->id; ?>

There is no $Auth->subdomain. If i use id; ?> i get a user id like for example 1111 for the currently logged in user. Is it possible to make an if statement check the table called "user" for the same user ID Auth->id outputs and if it finds one, check if "subdomain" for hat user is set to 1 and if it is it runs the code ?

CODE FROM THE SITE:

<?php if (!$Auth->loggedIn()): ?>


<?php else: ?>  

//Code to be run
<div>
    <label for="shortUrlDomain"><?php echo t("short_url_domain", "Short Url Domain"); ?>:</label>
    <select id="shortUrlDomain" name="shortUrlDomain" style="width: 100%;">
</div>

<?php endif; ?>

Upvotes: 0

Views: 77

Answers (1)

Joeri
Joeri

Reputation: 646

What are you using to pull data from your database? Assuming you also have $Auth->subdomain you could change the conditional to

 if (!$Auth->loggedIn() && $Auth->subdomain):

By the way you forgot to close your <select> tag and you haven't added any options

Upvotes: 1

Related Questions