Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Instructions
  2. ------------
  3.  
  4. - Go through this function line by line, and explain what the code does on each line
  5. - Are there any mistakes that need correcting?
  6. - What does the function do overall?
  7. - What use case do you think this function serves? What's the business logic behind needing this function?
  8. - Given your understanding of the function, what potential outputs do you expect from calling:  one("table_name", "column_name, "John")
  9.  
  10. <?php
  11. function check_name($table, $column, $source_value, $counter = "", $arr_where = array(), $file_extension)
  12. {
  13.    if($counter == "")
  14.    {
  15.       $attempted_new_name = $source_value.$file_extension;
  16.    }
  17.    else
  18.    {
  19.       $attempted_new_name = $source_value."-".$counter.$extension;
  20.    }
  21.    
  22.     $where = "";
  23.     if(count($arr_where) > 0)
  24.     {
  25.         $where = " AND ".implode(" AND ",$arr_where);
  26.     }
  27.  
  28.    $sql = "SELECT ".$column." FROM ".$table." WHERE ".$column." = ".sql_safe($attempted_new_name).$where;
  29.  
  30.    $result = mysqli_query_error_logged($sql);
  31.    if(mysqli_num_rows($result) == 0)
  32.    {
  33.       return $attempted_new_name;
  34.    }
  35.    else
  36.    {
  37.       if($counter = "")
  38.       {
  39.          $counter = 2;
  40.       }
  41.       else
  42.       {
  43.          $counter++;
  44.       }
  45.       return one($table, $column, $source_value, $counter, $arr_where, $file_extension);
  46.    }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement