Current location: Hot Scripts Forums » Programming Languages » PHP » Simple php/mysql question about date() & REMOTE_ADDR


Simple php/mysql question about date() & REMOTE_ADDR

Reply
  #1 (permalink)  
Old 06-07-08, 08:27 AM
jim14 jim14 is offline
New Member
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Simple php/mysql question about date() & REMOTE_ADDR

First of all i'm new to this forum, glad i found this wonderful place. I'm also new with programming and just came across the following problem; I have a PHP script with a mysql backend, i basically want it to save the IP address and date the user last logged in. I have done the changes in red myself (see below), but it just wont work. It just doesnt save the IP Address and Date in the user table 'logindate' and 'loginip' columns. No error or anything either.

Does anyone have an idea what i'm doing wrong? Thank you in advance!

Code:
	if ($mode == "login")
	{
		if (isset ($_POST['submit']))
		{
			$email = isset ($_POST['email']) ? trim ($_POST['email']) : '';
			$password = isset ($_POST['password']) ? trim ($_POST['password']) : '';
			$captcha = isset ($_POST['captcha']) ? trim ($_POST['captcha']) : '';

			if ((empty($_SESSION['captcha_code'])) || ($_SESSION['captcha_code'] != md5 ($captcha)))
				$error = 'Invalid Verification Code';
			else
			{
				$sql = "SELECT id FROM user WHERE email = '" . sql_quote ($email) . "' AND `password` = '" . md5 ($password) . "'";
				$user_id = sql_getfield ($sql, "id");

				if ($user_id)
				{
					$session_id = md5 (uniqid() + rand(1, 9999) * time());

					$sql = "DELETE FROM user_session WHERE user_id = $user_id";
					$db->sql_query ($sql);

					$sql = "INSERT INTO user_session (user_id, session_id, date)
						VALUES ($user_id, '$session_id', " . time() . ")";
					$db->sql_query ($sql);

	$ip = $_SERVER['REMOTE_ADDR'];
	$datem = date("j F Y, g:i a");
					$sql = "UPDATE user SET logindate = $datem AND loginip = $ip WHERE $user_id = id";
					$db->sql_query ($sql);
					$_SESSION['session_id'] = $session_id;

					redirect ("./index.php");
				}
				else $error = 'Email/Password not found';
			}
		}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-07-08, 08:53 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Try changing this line:

$sql = "UPDATE user SET logindate = $datem AND loginip = $ip WHERE $user_id = id";

to this:


$sql = "UPDATE user SET logindate = '$datem' AND loginip = '$ip' WHERE id = '$user_id'";
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-07-08, 10:36 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
UPDATE statements operate on a coma separated list of columns. There should not be an AND between the two columns you are updating -

Quote:
UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting date-string to Date object UnrealEd Everything Java 4 05-15-07 07:20 PM
question about date zoliky PHP 26 11-04-06 05:02 AM
need help simple question, but need it right. 0o0o0 PHP 3 01-31-06 05:21 PM
A simple php/mysql search based upon user input tapir PHP 1 01-31-05 07:40 AM
Simple question kashi PHP 5 08-13-04 11:23 PM


All times are GMT -5. The time now is 01:42 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.