0

So I am working on a simple website and I ran into a problem. I have a subscription based website and I have a date expired for when their subscription ends. This all works well, but when I tried to display the expiration date I ran into problems. The first 3 lines are what i have been trying. It seems as if the timestamp isnt correctly being transferred from the database because when I did my test at the button, this displayed the correct date. The top 3 lines always give me this: 1970/01/01

// Get Expiration Date
// Always gives me  1970/01/01
$datexpire  = "SELECT date-expire FROM users WHERE username='{$_SESSION['username']}'";
$timestamp = mysqli_query($link, $datexpire);
$date = date("Y/m/d",$timestamp);

//This works
$timestamp2 = 1537847863;
$date2 = date("Y/m/d",$timestamp2);

If anyone could help that would be much appreciated

2 Answers2

0

i think your code should be something like

 $datexpire  = "SELECT date-expire FROM users WHERE username='{$_SESSION['username']}'";
 $result = mysqli_query($link, $datexpire);
 $row=mysqli_fetch_assoc($result));
       $timestamp = $row['date_expire'];
       $date = date("Y/m/d", $timestamp);
       echo $date;

please check for column name.. if it is date-expire or date_expire ??? (dash or underscore ??)

0

mysqli_query returns a mysqli_result object or a boolean value. You want to fetch a row from your given object, like so:

$datexpire = "SELECT `date-expire` FROM users WHERE username='{$_SESSION['username']}'";
$result = mysqli_query($link, $datexpire);
$row = mysqli_fetch_assoc($result);
$date = date("Y/m/d", $row["date-expire"]);
HTMHell
  • 5,761
  • 5
  • 37
  • 79
  • This still returns the same date. – user10251809 Sep 09 '18 at 19:26
  • The problem is this " Permitted characters in unquoted identifiers: ASCII: [0-9,a-z,A-Z$_] (basic Latin letters, digits 0-9, dollar, underscore) " see source https://dev.mysql.com/doc/refman/8.0/en/identifiers.html you need backticks @user10251809 read the comments – Raymond Nijland Sep 09 '18 at 19:26
  • @RaymondNijland it's another problem with the code, you are correct. – HTMHell Sep 09 '18 at 19:28
  • @user10251809 You should try my updated code. If it doesn't work as expected, please tell us the result of `var_dump($result, $row);`. – HTMHell Sep 09 '18 at 19:30