Jump to content

Recommended Posts

can't get it to work

 

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to,UTC_TIMESTAMP) AS minutes FROM pengtracklog WHERE ip='x' ORDER BY ID ' at line 1

 

Query:

SELECT ID, TIMESTAMPDIFF(MINUTE,to,UTC_TIMESTAMP) AS minutes FROM pengtracklog WHERE ip='x' ORDER BY ID DESC LIMIT 1

here is the bigger picture of what i am trying to do:

 

$act = "test";
$user_id = 0;
$ip = $_SERVER['REMOTE_ADDR'];
$search = "SELECT ID, TIMESTAMPDIFF(MINUTE,to,UTC_TIMESTAMP) AS minutes 
FROM pengtracklog WHERE ip='{$ip}' ORDER BY ID DESC LIMIT 1";
$result = mysql_query($search) or die (mysql_error());

if($row = mysql_fetch_assoc($result)){
if($row['minutes'] > 5)
	$action = "UPDATE pengtracklog SET to=UTC_TIMESTAMP WHERE ID='{$row['ID']}'";
else
	$action = "INSERT INTO pengtracklog (ID, ID_user, action, ip, from, to) 
		VALUES (NULL, '{$user_id}', '{$act}', '{$ip}', UTC_TIMESTAMP, UTC_TIMESTAMP)
		WHERE ID='{$row['ID']}'";
}
else
$action = "INSERT INTO pengtracklog (ID, ID_user, action, ip, from, to) 
	VALUES (NULL, '{$user_id}', '{$act}', '{$ip}', UTC_TIMESTAMP, UTC_TIMESTAMP)
	WHERE ID='{$row['ID']}'";

$result = mysql_query($action) or die (mysql_error());

At least two of your column names are reserved keywords and either need to be renamed to something else or require special handling so that they are not treated as keywords and break the SQL syntax of your query - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

yep, working great now... this is the final TEST code incase anyone ever looks at this thread and is interested

 

$act = "test";
$user_id = 0;
$ip = $_SERVER['REMOTE_ADDR'];
$search = "SELECT ID, TIMESTAMPDIFF(MINUTE,totime,UTC_TIMESTAMP) AS minutes 
FROM pengtracklog WHERE ip='{$ip}' ORDER BY ID DESC LIMIT 1";
$result = mysql_query($search) or die (mysql_error());

if($row = mysql_fetch_assoc($result)){
if($row['minutes'] < 5)
	$action = "UPDATE pengtracklog SET totime=UTC_TIMESTAMP WHERE ID='{$row['ID']}'";
else
	$action = "INSERT INTO pengtracklog (ID, ID_user, action, ip, fromtime, totime) 
		VALUES (NULL, '{$user_id}', '{$act}', '{$ip}', UTC_TIMESTAMP, UTC_TIMESTAMP)";
}
else
$action = "INSERT INTO pengtracklog (ID, ID_user, action, ip, fromtime, totime) 
	VALUES (NULL, '{$user_id}', '{$act}', '{$ip}', UTC_TIMESTAMP, UTC_TIMESTAMP)";

$result = mysql_query($action) or die (mysql_error());

echo $action." [sUCCESS]<br />";
echo "MINUTES= ".$row['minutes'];

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.