Php not handling logic of true and false correctly -


i'm trying register new username in empty table in database. pass in username , uid , check see if user has name registered , accept request or if nobody has name can accept it. if there name registered user reject request.

it returns 'fail' bit of code below.

    if($name_found)      {     if ($udid_mismatch)     {     echo "fail";     }  

but table of db empty cannot true finds name or uid. can see mistake? i'm running in circles @ moment.

// localize variables $udid   = isset($_get['udid']) ? $_get['udid'] : ""; $name   = isset($_get['name']) ? $_get['name']  : "";   // protect against sql injections $udid  = mysql_real_escape_string($udid); $name  = mysql_real_escape_string($name);        $udid_mismatch=false; $name_found=false; $result = mysql_query("select udid ir_usernames name='$name'"); while( $row = mysql_fetch_assoc($result) ){     $name_found=true;     if($row['udid'] != $udid){     $udid_mismatch=true;     }     break; }      if($name_found)      {     if ($udid_mismatch)     {     echo "fail";     }      else      {     echo "success";     }     } else {  // insert username $retval = mysql_query("insert $table(         udid,         name     ) values (         '$udid',         '$name'     )",$conn);  if($retval) {     echo "success"; } else {     echo "fail_ret"; } } mysql_close($conn); 

many thanks, -code

your code seems fine , see difference in way select , insert queries done. 1 uses $table variable , other doesn't. sake of harmony, can try like:

$result = mysql_query("select udid $table name='$name'" , $conn); 

also might idea try debugging purposes.

$result = mysql_query("select * $table name='$name'" , $conn); while( $row = mysql_fetch_assoc($result) ){    print_r($row);    // other code } 

this dump out whole data, give hint on whats going on.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -