
Untitled
By: a guest on
Jun 11th, 2012 | syntax:
None | size: 1.36 KB | hits: 15 | expires: Never
//UPDATE to be EXPERT
$sql = "UPDATE users SET rank = '3' WHERE username = '$username'";
mysql_query($sql);
$days = 30;//Insert subscription for 30 days
$vip_ini = time();
$vip_end = time() + ($days*24*3600);
//Get id of user
$sql = "SELECT id FROM users WHERE username='$username'";
$result= mysql_query($sql);
$row = mysql_fetch_assoc($result);
//user id
$userid = $row[id];
//check first if user exist
$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";
$result = mysql_query($sql);
$total_records = mysql_num_rows($result);
if ($total_records>0){
$row = mysql_fetch_assoc($result);
$current_exp = $row['timestamp_expire'];
//if user still have some days with subscription then add the time to his account
if($current_exp > time()){
$vip_end = $vip_end + ($current_exp - time());
}
//delete all recrods in subscriptions table for this user
$sql = "DELETE FROM user_subscriptions WHERE user_id=$userid AND subscription_id='habbo_vip'";
mysql_query($sql);
}
//Insert a new subscription with the corresponding time
$sql = "INSERT INTO user_subscriptions(user_id, subscription_id, timestamp_activated, timestamp_expire) VALUES ($userid, 'habbo_vip', $vip_ini, $vip_end)";
mysql_query($sql);
?>