Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tinyf_users_update($uid,$name = NULL,$password = NULL ,$email = NULL,$isadmin = -1)
- {
- global $tf_handle;
- $id = (int)$uid;
- if($id == 0 )
- return false ;
- $n_isadmin = (int)$isadmin ; // if 0 = FALSE not int ,,, if int = 1
- $user = tinyf_users_get_by_id($id);
- if(!$user)
- return false;
- if ((empty($name)) && (empty($password)) && (empty($email)) && ($user -> isadmin == $n_isadmin))
- return false;
- $fields = array() ;
- $query = 'UPDATE `users` SET ' ;
- if(!empty($email))
- {
- $n_email = mysql_real_escape_string(strip_tags($email),$tf_handle);
- if(!filter_var($n_email,FILTER_VALIDATE_EMAIL))
- return false;
- $fields[count($fields)] = "`email` = '$n_email'";
- }
- if(!empty($name))
- {
- $n_name = mysql_real_escape_string(strip_tags($name),$tf_handle);
- $fields[count($fields)] = "`name` = '$n_name'";
- }
- if(!empty($password))
- {
- $n_pass = md5(mysql_real_escape_string(strip_tags($password),$tf_handle));
- $fields[count($fields)] = "`password` = '$n_pass'";
- }
- if($n_isadmin == -1)
- $n_isadmin = $user -> isadmin ;
- $fields[count($fields)] = "`isadmin` = $n_isadmin";
- $fcount = count($fields);
- if($fcount == 1)
- {
- $query .= $fields[0].'WHERE `id`= ' .$id ; // $query = 'UPDATE `users` SET '
- $qresult = mysql_query($query);
- if(!qresult)
- return false;
- else
- return true;
- }
- for($i = 0; $i < $fcount ; $i++)
- {
- $query .= $fields[$i];
- 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
- $query .=' , ';
- }
- $query .= ' WHERE `id` = '.$id;
- $qresult = mysql_query($query);
- if(!$qresult)
- return false;
- else
- return true;
- }
- include ('db.php') ;
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- $result = tinyf_users_update(6,'ggrgrgr','123456',NULL,5);
- if($result) //($uid,$name = NULL,$password = NULL ,$email = NULL,$isadmin = 0)
- echo 'success';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement