Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:55:37+00:00 2026-06-13T16:55:37+00:00

I am trying to make a simple query that will update a user database

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:55:38+00:00Added an answer on June 13, 2026 at 4:55 pm

    You can’t use INSERT to update existing records in the table. Use UPDATE query

    $sql="UPDATE CLL_users SET last_login= '$dateCreated' WHERE username= '$username'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make simple java code that will check if a table
I'm fairly new to SQL, and i'm trying to make a query with simple
I'm trying to make simple script using jquery $post function to pass data to
im trying to make a simple search on my database from the index action
I am trying to make a simple query to a small MYSQL table, but
I am trying to make a search form that will help users filter their
I'm trying to create a simple login system that will have the forms and
I have data in a simple txt file, a trying to query it (to
I'm currently trying to write a query that will return all users that have
I'm trying to make a MongoDB database for a simple voting system. If I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.