dpiw16824 2014-04-10 10:25
浏览 18
已采纳

如何显示登录用户的成员资格到期日期

I am pretty novice at php and hope that I can get some help. When we register a member to our website, we register them with full name, username, password, membership expiration date which goes into a sql database called USERS. Then when they log into the members area, it displayers their username and I want to display that particular users membership expiration date before that. Since I had the session name set with username I just used a simple echo command to display the username such as:

 <? echo "Welcome, {$_SESSION['username']}"; ?>

The problem however, is the line beneath that, echoing the currently logged in users expiration date. The code I'm using for it is here:

<?php

                        // Make a MySQL Connection
mysql_connect("server", "db", "pass") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT `Date` FROM `USERS` WHERE username= ".$_SESSION['username'])
or die(mysql_error());

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );

echo "Membership Expiration Date: ".$row['date'];
?>

I have edited this to include the code that was shared with me to get the WHERE clause.

The structure of my SQL table has 8 columns, id, username, fullname, password, email, active, code, Date, Hopefully that is what you were looking for.

  • 写回答

1条回答 默认 最新

  • dsdtumf776629385 2014-04-10 10:42
    关注

    Your mySQL request select ALL the rows from the table USERS. If you want to get the row of a specific user, you have to add an WHERE clause to your request:

    $result = mysql_query("SELECT date FROM USERS WHERE username = ".$_SESSION['username']);
    

    I invite you to document yourself about SQL and PHP, there are plenty of manuals/tutorials available on the web.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?