The below code is giving errors, I may have got the syntax wrong and I do not know where. The error is: near '(``last_online``) VALUE ('now()) WHERE (users.id = 55)' at line 1
.
The PHP code:
<?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());
The syntax for the UPDATE
statement is:
UPDATE table
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
Thus, you should use the following instead to update both fields in a single statement:
UPDATE `users`
SET `last_online` = now(),
`users_ip` = '$user_ip'
WHERE (users.id = $id)
The VALUES
keyword is used in the INSERT
statement.