-1

I wrote a update function when user logins and logouts, the code is

function update_status_offline($id) {
$id = $_SESSION['id'];
mysql_query("UPDATE users SET status = 0 WHERE id = $id"); }

And the same for online status, everything works great but when I removed

header('Location: ../');

It show me following error:

Warning: Missing argument 1 for update_status_offline() (...)

What could be wrong in the code ?

manlio
  • 18,345
  • 14
  • 76
  • 126
Piggie
  • 27
  • 1
  • 7
  • 2
    [Please, don't use `mysql_*` functions in new code](http://stackoverflow.com/q/12859942). They are no longer maintained and the deprecation process has begun, see the [red box](http://php.net/mysql-connect). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli); [this article](http://php.net/mysqlinfo.api.choosing) will help you decide which. If you choose PDO, [here is a good tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – Geek Num 88 Nov 18 '12 at 17:04

2 Answers2

1

You are not passing the argument to the function

If you have:

update_status_offline();

it needs to be changed to:

update_status_offline($id);

or alternatively remove $id from the function as it seems it is already being set.

function update_status_offline(){
    $id = $_SESSION['id'];
    mysql_query("UPDATE users SET status = 0 WHERE id = $id"); 
}
Samuel Cook
  • 16,620
  • 7
  • 50
  • 62
0

Try this (no arg)

function update_status_offline()
{
    $id = $_SESSION['id'];
    mysql_query("UPDATE users SET status = 0 WHERE id = $id"); 
}
Ziumin
  • 4,800
  • 1
  • 27
  • 34