//Registration is a complex thing. Lets simply it and only add the referral if its set to save query if it isn't.. if(isset($_POST['referral'])) { //If this is true you are using the ID number.. Easy enough just validate it and continue if(preg_match("/[^0-9]/", $_POST['referral'])) { //Validate the variable we are about to use.. $_POST['referral'] = (int) $_POST['referral']; //Validate they exist.. $result = db_query("SELECT realname FROM {$db_prefix}members WHERE ID_MEMBER == " . $_POST['referral'], __FILE__, __LINE__); //If we got something update Something.. if(!empty($result)) updateMemberData($memberID, array ( 'referral' => $_POST['referral'], )); else fatal_lang_error(453, false); } else { //Well they are trying to find the username itself.. $_POST['referral'] = trim(preg_replace('~[\s]~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['referral'])); $result = db_query("SELECT ID_MEMBER FROM {$db_prefix}members WHERE realname == " . $_POST['referral'], __FILE__, __LINE__); //If we got something update Something.. if(!empty($result)) { while ($row = mysql_fetch_assoc($request)) updateMemberData($memberID, array ( 'referral' => $row[0], )); } else fatal_lang_error(453, false); } }