I am trying to make a simple query that will update a user database with the time that the user last logged in. My SQL data base has several columns id | first_name | last_name | username| password | date_created | last_login The query I am trying to run is:
$sql="INSERT INTO (CLL_users) SET last_login= $dateCreated WHERE username= $username";
$result=mysql_query($sql);
Here is the entire code of the page loaded after successful validation and I do realize its the worst method to use because of SQL injection but once I get the proper query down I will recode it for PDO prepared statements this was just an example I found on another website and I am modifying it to add the last_login parameter.
<?php
session_start();
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="XXXXX"; // Mysql password
$db_name="DB"; // Database name
$tbl_name="users"; // Table name
date_default_timezone_set('America/Chicago');
$dateCreated = date('m/d/Y h:i:s a', time());
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="INSERT INTO (CLL_users) SET last_login= $dateCreated WHERE username= $username";
$result=mysql_query($sql);
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<head>
<title> Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="CLL.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php echo $dateCreated ?>
<p>Login Successful</p>
</body>
</html>
INSERTcreate a new entry in database. For update you need to useUPDATE..