Jump to content

creating a "last login" date for users.


kendallkamikaze

Recommended Posts

I've been working on this all night...in my sql under my "players" table I added a lastlog field.

 

ive been trying to get it to post the date into the lastlog field but I cant seem to get the coding right. I've been putting the code in "loggedin.php" which is where you get directed to once you log in.

 

<?php

mysql_query("update player set lastlog=NOW() where id='$id'");

?>

 

 

please help??  :-[

Link to comment
Share on other sites

you may also need to have single quotes around NOW()

 

 

NOW() is a function.  Quotes are only put around strings.

 

 

do i have to have it set to timestamp or can i just use the date stamp?

It needs to be one of MySQL's built in timestamp types.  datetime for example.

Link to comment
Share on other sites

<?php
require_once 'databaseconnection.php';


mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$Username=$_POST['Username']; 
$Password=$_POST['Password'];

$Username= stripslashes($Username);
$Password = stripslashes($Password);
$Username = mysql_real_escape_string($Username);
$Password = mysql_real_escape_string($Password);

$sql="SELECT * FROM player WHERE Username='$Username' and Password='$Password'";
$result=mysql_query($sql);

$id=$r["id"];


$count=mysql_num_rows($result);

if($count==1){

session_register("Username");
session_register("Password"); 
session_register("id"); 
header("location:loggedin.php");
$date = date("m/d/y");

$update = @mysql_query("UPDATE player SET lastlog = '$date' WHERE id = '".$_SESSION['id']."'");

setcookie("Username", "$Username");
setcookie("Password", "$Password");
setcookie("id", "$id");

$playerid=$_POST['playerid'];

mysql_query("UPDATE player SET lastlog=NOW() where playerid='$id'");

}
else {
echo "You have entered the wrong login information";
}
?>

 

 

this is what i have, but for some reason the DB is not reading it and setting the date :/

Link to comment
Share on other sites

Change mysql_error to mysql_error()

<?php
require_once 'databaseconnection.php';


mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$Username=$_POST['Username']; 
$Password=$_POST['Password'];

$Username= stripslashes($Username);
$Password = stripslashes($Password);
$Username = mysql_real_escape_string($Username);
$Password = mysql_real_escape_string($Password);

$sql="SELECT * FROM player WHERE Username='$Username' and Password='$Password'";
$result=mysql_query($sql);

$id=$r["id"];


$count=mysql_num_rows($result);

if($count==1){

session_register("Username");
session_register("Password"); 
session_register("id"); 
header("location:loggedin.php");
$date = date("m/d/y");

$update = @mysql_query("UPDATE player SET lastlog = '$date' WHERE id = '".$_SESSION['id']."'");

setcookie("Username", "$Username");
setcookie("Password", "$Password");
setcookie("id", "$id");

$playerid=$_POST['playerid'];

mysql_query("UPDATE player SET lastlog=NOW() where playerid='$id'")or die mysql_error();

}
else {
echo "You have entered the wrong login information";
}
?>

 

i get an error with this code.

 

with this code:

<?php
require_once 'databaseconnection.php';


mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$Username=$_POST['Username']; 
$Password=$_POST['Password'];

$Username= stripslashes($Username);
$Password = stripslashes($Password);
$Username = mysql_real_escape_string($Username);
$Password = mysql_real_escape_string($Password);

$sql="SELECT * FROM player WHERE Username='$Username' and Password='$Password'";
$result=mysql_query($sql);

$id=$r["id"];


$count=mysql_num_rows($result);

if($count==1){

session_register("Username");
session_register("Password"); 
session_register("id"); 
header("location:loggedin.php");
$date = date("m/d/y");

$update = @mysql_query("UPDATE player SET lastlog = '$date' WHERE id = '".$_SESSION['id']."'");

setcookie("Username", "$Username");
setcookie("Password", "$Password");
setcookie("id", "$id");

$playerid=$_POST['playerid'];

mysql_query("UPDATE player SET lastlog=NOW() where playerid='$id'")or mysql_error();

}
else {
echo "You have entered the wrong login information";
}
?>

there is no error but its still not functioning.

Link to comment
Share on other sites

If you have php MyAdmin, do this:

1. go to the database you are using

2. Click on "SQL"

3. Type this:

    DESCRIBE player

4. Press Go

 

 

If you are using SSH, do this:

1. type this (press enter):

    USE db_name

2. type this (press enter):

    DESCRIBE player

 

Once you have done one of the above, copy and paste the results here

Link to comment
Share on other sites

If you have php MyAdmin, do this:

1. go to the database you are using

2. Click on "SQL"

3. Type this:

    DESCRIBE player

4. Press Go

 

 

If you are using SSH, do this:

1. type this (press enter):

    USE db_name

2. type this (press enter):

    DESCRIBE player

 

Once you have done one of the above, copy and paste the results here

 

id	int(10) unsigned	NO	PRI	NULL	auto_increment
	 	 	Username	text	NO	MUL	NULL	 
	 	 	Password	text	NO	 	NULL	 
	 	 	Playername	text	NO	MUL	NULL	 
	 	 	Firstname	text	NO	 	NULL	 
	 	 	Email	text	NO	 	NULL	 
	 	 	TOS	text	NO	 	NULL	 
	 	 	Guidelines	text	NO	 	NULL	 
	 	 	lastlog	date	NO	 	NULL	 
	 	 	Points	int(11)	NO	 	NULL	 
	 	 	AcademyLevel	text	NO	 	NULL	 
	 	 	Associations	text	NO	 	NULL	 
	 	 	Barns	text	NO	 	NULL	 
	 	 	Money	int(11)	NO	 	NULL	 
	 	 	Description	text	NO	 	NULL	 
	 	 	Status	text	NO	 	NULL	 
	 	 	Behavioural	text	NO	 	NULL	 
	 	 	GirlScout	int(11)	NO	 	NULL	 
	 	 	YourMom	int(11)	NO	 	NULL	 
	 	 	Tutor	text	NO	 	NULL	 
	 	 	TraitAdd	text	NO	 	NULL	 
	 	 	onstatus	text	NO	 	NULL	 
	 	 	chatlli	timestamp	NO	 	0000-00-00 00:00:00	 
	 	 	banfromchat	varchar(255)	NO	 	no	 
	 	 	banfromchatreason	varchar(255)	NO	 	NULL	 
	 	 	TraitNumber	int(11)	NO	 	NULL	 
	 	 	BarnShow	text	NO	 	NULL	 
	 	 	banreason	text	NO	 	NULL	 
	 	 	special	text	NO	 	NULL	 
	 	 	refered	varchar(32)	NO	 	No	 
	 	 	referer	text	NO	 	NULL	 
	 	 	referalpoints	int(11)	NO	 	NULL	 
	 	 	vet	text	NO	 	NULL	 
	 	 	farrier	text	NO	 	NULL	 
	 	 	trainer	text	NO	 	NULL	 
	 	 	breeder	text	NO	 	NULL	 
	 	 	Team	int(11)	NO	 	1	 
	 	 	tstatus	text	NO	 	NULL	 
	 	 	tpoints	int(11)	NO	 	NULL	 
	 	 	IP	varchar(50)	NO	 	NULL	 
	 	 	Browse	varchar(50)	NO	 	NULL	 
	 	 	layout	varchar(20)	NO	 	layouts_phism.php	 
	 	 	gold	text	NO	 	NULL	 
	 	 	awards	text	NO	 	NULL	 

 

PS; they make me smile too. hhahahaha sorry i just read your icon and no im not a lesbian.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.