Advertisement
Vendettaaaa

Untitled

Jun 28th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. function tinyf_users_update($uid,$name = NULL,$password = NULL ,$email = NULL,$isadmin = -1)
  2. {
  3.     global $tf_handle;
  4.     $id =  (int)$uid;
  5.     if($id == 0 )
  6.         return false ;
  7.     $n_isadmin = (int)$isadmin ; // if 0 = FALSE not int ,,, if int  = 1
  8.     $user = tinyf_users_get_by_id($id);
  9.     if(!$user) 
  10.         return false;
  11.     if ((empty($name)) && (empty($password)) && (empty($email)) && ($user -> isadmin == $n_isadmin))
  12.         return false;  
  13.     $fields = array() ;
  14.     $query = 'UPDATE `users` SET ' ;
  15.    
  16.     if(!empty($email))
  17.         {
  18.             $n_email = mysql_real_escape_string(strip_tags($email),$tf_handle);
  19.             if(!filter_var($n_email,FILTER_VALIDATE_EMAIL))
  20.                 return false;
  21.            
  22.             $fields[count($fields)] = "`email` = '$n_email'";
  23.         }  
  24.    
  25.     if(!empty($name))
  26.         {
  27.             $n_name = mysql_real_escape_string(strip_tags($name),$tf_handle);
  28.             $fields[count($fields)] = "`name` = '$n_name'";
  29.         }
  30.     if(!empty($password))
  31.         {
  32.             $n_pass = md5(mysql_real_escape_string(strip_tags($password),$tf_handle));
  33.             $fields[count($fields)] = "`password` = '$n_pass'";
  34.         }      
  35.  
  36.     if($n_isadmin == -1)
  37.         $n_isadmin = $user -> isadmin  ;       
  38.     $fields[count($fields)] = "`isadmin` = $n_isadmin";
  39.    
  40.     $fcount = count($fields);
  41.    
  42.     if($fcount == 1)
  43.      {
  44.         $query .= $fields[0].'WHERE `id`= ' .$id ; //   $query = 'UPDATE `users` SET '
  45.         $qresult = mysql_query($query);
  46.         if(!qresult)
  47.             return false;    
  48.         else
  49.             return true;
  50.        
  51.        
  52.      }  
  53.     for($i = 0; $i < $fcount ; $i++)
  54.      {
  55.         $query .= $fields[$i];
  56.         if($i != ($fcount - 1)) // i = 0 that the first element in the array .. 2 will be - 1 last 3shan hwa by3ed el array mn wa7ed :D
  57.             $query .=' , ';
  58.      }
  59.      
  60.      $query .= ' WHERE `id` = '.$id;
  61.  
  62.      $qresult = mysql_query($query);
  63.      if(!$qresult)
  64.         return false;
  65.      else
  66.         return true;
  67.  
  68. }
  69.  
  70.  
  71.  
  72. include ('db.php') ;
  73. error_reporting(E_ALL);
  74. ini_set('display_errors', 1);
  75. $result = tinyf_users_update(6,'ggrgrgr','123456',NULL,5);
  76. if($result) //($uid,$name = NULL,$password = NULL ,$email = NULL,$isadmin = 0)
  77.     echo 'success';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement