Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 11th, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //UPDATE to be EXPERT
  2. $sql = "UPDATE users SET rank = '3' WHERE username = '$username'";
  3. mysql_query($sql);
  4.  
  5. $days = 30;//Insert subscription for 30 days
  6. $vip_ini = time();
  7. $vip_end = time() + ($days*24*3600);
  8.  
  9. //Get id of user
  10. $sql   = "SELECT id FROM users WHERE username='$username'";
  11. $result= mysql_query($sql);
  12. $row     = mysql_fetch_assoc($result);
  13.  
  14. //user id
  15. $userid = $row[id];
  16.  
  17. //check first if user exist
  18. $sql   = "SELECT user_id, timestamp_expire FROM user_subscriptions WHERE user_id=$userid AND subscription_id='habbo_vip' ORDER BY timestamp_expire DESC LIMIT 1";
  19. $result = mysql_query($sql);
  20. $total_records = mysql_num_rows($result);
  21.  
  22. if ($total_records>0){
  23.   $row = mysql_fetch_assoc($result);
  24.   $current_exp = $row['timestamp_expire'];
  25.  
  26.   //if user still have some days with subscription then add the time to his account
  27.   if($current_exp > time()){
  28.     $vip_end = $vip_end + ($current_exp - time());  
  29.   }
  30.  
  31.   //delete all recrods in subscriptions table for this user
  32.   $sql   = "DELETE FROM user_subscriptions WHERE user_id=$userid AND subscription_id='habbo_vip'";
  33.   mysql_query($sql);
  34. }
  35.  
  36. //Insert a new subscription with the corresponding time
  37. $sql   = "INSERT INTO user_subscriptions(user_id, subscription_id, timestamp_activated, timestamp_expire) VALUES ($userid, 'habbo_vip', $vip_ini, $vip_end)";
  38. mysql_query($sql);
  39.  
  40.  
  41. ?>