Checking if variable is 0 as opposed to NULL/Empty...


Posted on 16th Feb 2014 07:03 pm by admin

I'm trying to write some code that will retrieve a user's access level from my database and if it doesn't return any values then I want to set the access variable to 2.

I'm using...

Did you know?Explore Trending and Topic pages for more stories like this.
$access_id = $useraccess["0"]["access_id"];

if (!$access_id) {$access_id = '2';}

Where $useraccess is the array I've got from the database. I set the variable $access_id to whatever the user's access_id field contains. Then I check the variable because if the access_id field is empty then I know the user hasn't had one specified and should be given the site default. The problem is one of the access levels is '0' which is returning an empty value and then setting it to two.

Has anyone any idea how to stop this please?
No comments posted yet

Your Answer:

Login to answer
50 Like 39 Dislike
Previous forums Next forums
Other forums

Is it a good practice to store user info. in sessions?
I am making a user class for my script which stores all the user information in sessions. It takes u

Remove Rows From Database ad
Hi All,

I have this:

Code: [Select]<?php
session_start();
include('../com

Newb advice
Hi all,

I'm a flash front end designer and I've taken on a project that needs some back end p

Not loading image
When this function gets loaded it doesn't load the image just trying to figure out why.

Code:

How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou

Checking if multidimensional array is empty?
I have a for with multiple test input fields. Specifically the user submits multiple names and ages

help removing unwanted graphic
How do I remove the small elongated rectangular shape between the "Latest post" and "

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

Help! refer to a friend script with captcha code
Hi guys, I am posting on here in desperate need for some help with an ongoing search I have been doi

SELECT * FROM users WHERE Users are not in Blocked
How do I select all users from users table where there users_id is not stored in the block table

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash