Al ejecutar el script que pongo mas abajo obtengo el siguiente 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 '' at line 1
Fijaros que '' es un par de comillas simples y no una doble. Pero no encuentro donde esta el error, ojala alguien pueda ayudarme. Gracias.
Código PHP:
<?php
require_once("connect.php");
require_once("session.php");
if(!isset($_POST['upd']))
{
$query = "update `online` set `last` = now() where `userid` = ".$_SESSION['loggedinid'];
mysql_query($query)
or die(mysql_error());
$tryupdate = mysql_affected_rows();
if(!$tryupdate != 0)
{
$query = "insert into `online` (`username`,`userid`,`last`)
values ('".mysql_escape_string($_SESSION['loggedin'])."',".$_SESSION['loggedinid'].",now())";
mysql_query($query)
or die(mysql_error());
}
}
$query = "select * from `online` where `last` > '".date("Y-m-d H:i:s", time() - 3)."' order by `username`";
$getnames = mysql_query($query)
or die(mysql_error()); // get list of users who are online (within 30 seconds)
echo '<table><tr><td width="500">Who is online?</td></tr>';
while($person = mysql_fetch_array($getnames))
{
echo '<tr><td width="500">'.$person['username'].'</td></tr>';
}
echo '</table>';
if(isset($_POST['upd']))
{
$query = "update `online` set `last` = now() where `userid` = ".$_POST['who'];
mysql_query($query)
or die(mysql_error());
}
?>