duanjiushu5063 2018-01-22 10:09
浏览 67

php mysql帐户订阅到期

I have a mysql database of users which has a subscription expiry field (sub_expire) which is timestamp format at present and also another field (active) which is enum yes or no which is yes allows login and if no refuses login.

How do I using php check if the subscription expiry date has either been reached or has passed upon a user attempting to login and then update the active field to no so that the user is unable to login.

Many thanks in advance

  • 写回答

1条回答 默认 最新

  • dongliuzhuan1219 2018-01-22 11:39
    关注

    This gets if the users by $username and checks if sub_expire smaller than the current time/date. if yes active get set to no
    As mentioned by @AgeDeO you should not save active and sub_expire as both have the same usage

    $SQL_CONN = mysqli ("host",
                        "user",
                        "password",
                        "dbname",
                        "port");
    
    $sqlStm = $SQL_CONN->prepare("select u.user_id, u.sub_expire < NOW from users u where u.name = ?;");
    $sqlStm->bind_param ("s", $username);
    
    $sqlStm->execute();
    
    $sqlStm->store_result();
    
    $sqlStm->bind_result($id, $active);
    
    $sqlStm->free_result();
    $sqlStm->close();
    
    if(!$active) {
    
      $sqlStm = $SQL_CONN->prepare("update users set active =`no` WHERE user_id = ?");
      $sqlStm->bind_param ("i", $user_id);
    
      $sqlStm->execute();
      $sqlStm->free_result();
      $sqlStm->close();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100