w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Boolean Logical Syntax and MYSQL syntax Issue

What if you split your query into two parts? Querying for one set of information at a time will make things simpler and easier to debug.

I could imagine doing something that looks like this (in pseudo-code):

query = "SELECT username 
         FROM `userinfo` `u3` 
         WHERE `u3`.`username` LIKE '%".mysql_real_escape_string($data)."%'

             OR `u3`.`email` LIKE '%".mysql_real_escape_string($data)."%'"

var result = db.execute(query);
// set to true if the above query returns at least one row
bool user_exists = (result.RowCount() > 0)
var username = (user_exists)? result.GetRow().GetField("username") : null;

if(user_exists)//user exist
{
    value = username;
    //user exists but skip
} // ....

(I've only replicated the functionality pertaining to your UNION's first SELECT statement; the logic associated with the second statement can be similarly rewritten.)





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.