2012-09-03 5 views
1

아래 코드는 오류가 발생합니다. 구문이 잘못되었을 수 있으며 어디에 있는지 잘 모릅니다. 오류 : near '(``last_online``) VALUE ('now()) WHERE (users.id = 55)' at line 1.SQL을 사용하여 동시에 두 필드를 업데이트하십시오.

PHP 코드 :

<?php 
include 'dbc.php'; 
session_start(); 
$user_ip = $_SERVER['REMOTE_ADDR']; 

$id = $_SESSION['user_id']; 

$sql_insert1 = "UPDATE `users` SET (`last_online`) 
      VALUES 
      ('now()) WHERE (users.id = $id)"; 

mysql_query($sql_insert1) or die("Insertion Failed:" . mysql_error()); 
$sql_insert2 = "UPDATE `users` SET (`users_ip`) 
      VALUES 
      ('$user_ip') WHERE (users.id = $id)"; 

mysql_query($sql_insert2) or die("Insertion Failed:" . mysql_error()); 

답변

3

UPDATE 문의 구문은 다음과 같습니다 따라서

UPDATE table 
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... 
[WHERE where_condition] 

, 당신은 하나의 문에서 두 필드를 업데이트하는 대신 다음을 사용한다 :

UPDATE `users` 
SET `last_online` = now(), 
    `users_ip` = '$user_ip' 
WHERE (users.id = $id) 

VALUES 키워드는에서 사용됩니다.3210 성명.

+0

이제이 오류가 발생합니다. '('last_online') = now() WHERE (users.id = 55)'on line 1 –

+0

'last_online' 필드를 괄호로 묶고 있습니까? 그냥'last_online' = now()를 사용하지 마십시오 –

+0

이 코드로 해결해 주셔서 감사합니다

관련 문제