Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Timestamps... Can't Seem to get it to work.....

Timestamps... Can't Seem to get it to work.....

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databasehelpmysqlannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Okay, I tried using W3Schools to "UPDATE" a timestamp, upon logging in, here is my code:

    $sql = mysql_query('UPDATE `DBNAME`.`TABLENAME` SET `lastactive` = NOW() WHERE `TABLENAME`.`username` = $username ;');

    Here is the login code:

    if(isset($_POST['login'])){
    $username= trim($_POST['username']);
    $password = trim(md5($_POST['password']));
    if($username == NULL OR $password == NULL){
    $final_report.="Please complete all the fields below..";
    }else{
    $check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
    if(mysql_num_rows($check_user_data) == 0){
    $final_report.="The username that you submitted does not exist..";
    }else{
    $get_user_data = mysql_fetch_array($check_user_data);
    if($get_user_data['password'] == $password){
    $start_idsess = $_SESSION['username'] = "".$get_user_data['username']."";
    $start_passsess = $_SESSION['password'] = "".$get_user_data['password']."";

    That is the code above the timestamp issue. The page loads and everything, it just doesn't update it into the database... Please Help. Thanks!

    G F 2 Replies Last reply
    0
    • L Lost User

      Okay, I tried using W3Schools to "UPDATE" a timestamp, upon logging in, here is my code:

      $sql = mysql_query('UPDATE `DBNAME`.`TABLENAME` SET `lastactive` = NOW() WHERE `TABLENAME`.`username` = $username ;');

      Here is the login code:

      if(isset($_POST['login'])){
      $username= trim($_POST['username']);
      $password = trim(md5($_POST['password']));
      if($username == NULL OR $password == NULL){
      $final_report.="Please complete all the fields below..";
      }else{
      $check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
      if(mysql_num_rows($check_user_data) == 0){
      $final_report.="The username that you submitted does not exist..";
      }else{
      $get_user_data = mysql_fetch_array($check_user_data);
      if($get_user_data['password'] == $password){
      $start_idsess = $_SESSION['username'] = "".$get_user_data['username']."";
      $start_passsess = $_SESSION['password'] = "".$get_user_data['password']."";

      That is the code above the timestamp issue. The page loads and everything, it just doesn't update it into the database... Please Help. Thanks!

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      The user name will be a text string, so you need to enclose it in quotes:

      $sql = mysql_query("UPDATE members SET lastactive=NOW() WHERE username='$username'");

      I've also replaced the DBNAME and TABLENAME with the actual name of your table, and replaced the single quotes around the SQL string with double quotes so that $username will be expanded. Also, instead of:

      $password = trim(md5($_POST['password']));

      you probably want:

      $password = md5(trim($_POST['password']));

      - an MD5 hash won't have any spaces in it, but the password you pass to it might.

      1 Reply Last reply
      0
      • L Lost User

        Okay, I tried using W3Schools to "UPDATE" a timestamp, upon logging in, here is my code:

        $sql = mysql_query('UPDATE `DBNAME`.`TABLENAME` SET `lastactive` = NOW() WHERE `TABLENAME`.`username` = $username ;');

        Here is the login code:

        if(isset($_POST['login'])){
        $username= trim($_POST['username']);
        $password = trim(md5($_POST['password']));
        if($username == NULL OR $password == NULL){
        $final_report.="Please complete all the fields below..";
        }else{
        $check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
        if(mysql_num_rows($check_user_data) == 0){
        $final_report.="The username that you submitted does not exist..";
        }else{
        $get_user_data = mysql_fetch_array($check_user_data);
        if($get_user_data['password'] == $password){
        $start_idsess = $_SESSION['username'] = "".$get_user_data['username']."";
        $start_passsess = $_SESSION['password'] = "".$get_user_data['password']."";

        That is the code above the timestamp issue. The page loads and everything, it just doesn't update it into the database... Please Help. Thanks!

        F Offline
        F Offline
        fly904
        wrote on last edited by
        #3

        You are still not sanitizing your data inputs, to protect you from SQL Injection Attacks[^]. Use: mysql_real_escape_string[^]

        thebiostyle wrote:

        "".$get_user_data['username'].""

        That does nothing useful. You don't need the empty strings either side, they do nothing, just have the variable.

        thebiostyle wrote:

        $start_passsess = $_SESSION['password'] = "".$get_user_data['password']."";

        Are you sure you want to keep the hashed password as a session variable?

        If at first you don't succeed, you're not Chuck Norris.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups