简体   繁体   中英

PHP Insert value if column is null

I'm working on a loader that will load a file once the user authenticated correctly, but before I want to start my file stream I want to check their HWID to check so it matches the HWID on the database and I have managed to do it and I do it like this:

function validate_Hwid(){
            global $db, $encryptionEngine;
            if (isset($_GET['username']) && isset($_GET['hwid'])) {
                $username = $encryptionEngine->init($_GET['username'],"decrypt");
                $hwid = $encryptionEngine->init($_GET['hwid'],"decrypt");
                $query = $db->simple_select("users", "*", "LOWER(username)='".$db->escape_string(my_strtolower($username))."'", array('limit' => 1));
                $user = $db->fetch_array($query);
                if ($hwid == $user['hwid']) {
                    return 1;
                } else {
                    return 0;
                }
            } else {
                return 0;
            }
        }

but I have a problem, if the user never logged in before the HWID on the DB will be null, how can I change so if HWID on the user is null, than insert the string I provide?

if ($user['hwid'] == null)
{
    // insert and call func again
} elseif ($hwid == $user['hwid']) {
    return 1;
} else {
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM