Update Login Date
Moderator: General Moderators
Update Login Date
I have a login page that I need to send the current date/time to a field in the database. I am assuming the now() function. But I don't know what it would look like.
Any ideas?
Any ideas?
new issue...
I got to work in phpMyAdmin but when I stick it on the page it does not work. Here is my code:
Any ideas?
Code: Select all
<?php
/* Check User Script */
session_start(); // Start Session
include 'db.php';
// Convert to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
include 'login.php';
exit();
}
// Convert password to md5 hash
$password = md5($password);
// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND closed='0' AND active='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// update last login
$last_login = "UPDATE users SET last_login = NOW() WHERE username = '$username' AND password = '$password'";
// Register some session variables!
session_register('first_name');
$_SESSION['first_name'] = $first_name;
session_register('last_name');
$_SESSION['last_name'] = $last_name;
session_register('email_address');
$_SESSION['email_address'] = $email_address;
session_register('signup_date');
$_SESSION['signup_date'] = $signup_date;
session_register('userid');
$_SESSION['userid'] = $userid;
session_register('address');
$_SESSION['address'] = $address;
session_register('city');
$_SESSION['city'] = $city;
session_register('state');
$_SESSION['state'] = $state;
session_register('zip');
$_SESSION['zip'] = $zip;
session_register('phone1');
$_SESSION['phone1'] = $phone1;
session_register('phone2');
$_SESSION['phone2'] = $phone2;
session_register('birth');
$_SESSION['birth'] = $birth;
session_register('dl');
$_SESSION['dl'] = $dl;
session_register('username');
$_SESSION['username'] = $username;
session_register('password');
$_SESSION['password'] = $password;
session_register('decrypted_password');
$_SESSION['decrypted_password'] = $decrypted_password;
header("Location: userindex.php");
}
} else {
echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />
Please try again!<br />";
include 'login.php';
}
?>You do
but never actually run it 
Code: Select all
$last_login = "UPDATE users SET last_login = NOW() WHERE username = '$username' AND password = '$password'";Code: Select all
mysql_query($last_login) or die(mysql_error());Here is question...
Here is a question along the same lines...
I am creating a variable for a query. I'm quering the MONTH field of a table in the database. It is a INT field so it has numbers (ie: January would be recorded as 1, February as 2, etc.).
What I need to do is grab the current month from the server ("now()" statement) and grabe the month of that variable as a number so it would query correctly.
For example (the code is wrong of course):
The "$month" must result in a number.
Ideas on that?
I guess the summary questions is... how do you make the current date a variable?
I am creating a variable for a query. I'm quering the MONTH field of a table in the database. It is a INT field so it has numbers (ie: January would be recorded as 1, February as 2, etc.).
What I need to do is grab the current month from the server ("now()" statement) and grabe the month of that variable as a number so it would query correctly.
For example (the code is wrong of course):
Code: Select all
$month = now(month_id);
//then the query
...SELECT * FROM table WHERE month = "$month"....Ideas on that?
I guess the summary questions is... how do you make the current date a variable?
Ahhh, getting closer...
This works...
Now I have to figure out how to format the "$monthALL" in to another variable that only shows the month. This give me an error:
Code: Select all
<?php
$monthAll = date("Y-m-d H:i:s");
?>Code: Select all
<?php
$monthNow = "echo FormatDateTime($monthAll, "m")";
?>I do the following whenever I want the current time to be inserted into the database.
So, as you can see I use the "CURRENT_TIMESTAMP" SQL command for inserting the current time.
Code: Select all
UPDATE table_name SET colum1 = '".$variable1."', colum2 = '".$variable2."', date_modified = CURRENT_TIMESTAMP WHERE column1 = '".$variable."'";- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
On a side note, this kind of thing,
is going to cause problems, $_SESSION and session_register() should not be used together. Instead you should just have:
Mac
Code: Select all
session_register('first_name');
$_SESSION['first_name'] = $first_name;Code: Select all
$_SESSION['first_name'] = $first_name;