Page 1 of 1

why would't this work?

Posted: Fri Nov 01, 2002 8:09 am
by qads

Code: Select all

<?php
<?php 
@mysql_connect('*****','*****','*****') or die ("error: 
connecting db host..."); // db host 
@mysql_select_db('clancek') or die ("Error: Connecting database..."); 
//database name 
$timeoutseconds = 30; //time limit in secs before the old records are 
deleted... 


$timestamp = time(); 
$timeout = $timestamp-$timeoutseconds; 
$remote = $HTTP_SERVER_VARSї"REMOTE_ADDR"]; 
$insert = mysql_query("INSERT INTO q_useronline VALUES 
'timestamp','$remote')"); 
if(!($insert)) { 
 print "Useronline Insert Failed"; 
} 
$delete = mysql_query("DELETE FROM q_useronline WHERE 
timestamp<$timeout"); 
if(!($delete)) { 
 print "Useronline Delete Failed"; 
} 
$result = mysql_query("SELECT DISTINCT ip FROM q_useronline"); 
if(!($result)) { 
 print "Useronline Select Error > "; 
} 
$user = mysql_num_rows($result); 
if($user == 1) { 
 $online = "<b>Users Online:</b> $user\n"; 
} else { 
 $online = "<b>Users Online:</b> $user\n"; 
} 
?>
?>
phpinfo : http://www.host.sk/phpinfo.html

error: Useronline Insert Failed

works great at localhost with php version 4.0.1, but it does't on the above host :? .

thanks for your help.

Posted: Fri Nov 01, 2002 8:28 am
by volka
try

Code: Select all

$query = "INSERT INTO q_useronline VALUES 'timestamp','$remote')";
$insert = mysql_query($query) or die($query.' :'.mysql_error());

Posted: Fri Nov 01, 2002 8:29 am
by twigletmac
Change:

Code: Select all

$insert = mysql_query("INSERT INTO q_useronline VALUES  
'timestamp','$remote')");
to

Code: Select all

$sql = "INSERT INTO q_useronline VALUES 'timestamp','$remote')";  
$insert = mysql_query($sql);
Instead of:

Code: Select all

print "Useronline Insert Failed";
use

Code: Select all

echo mysql_error().'<p>'.$sql.'</p>';
to get a more useful error message.

Then you should be able to see that you are missing an opening parenthesis after VALUES in the SQL statement.

Mac

Posted: Fri Nov 01, 2002 9:00 am
by superwormy
You have an error in your syntax here:


$insert = mysql_query("INSERT INTO q_useronline VALUES 'timestamp','$remote')");


You're missing the leading ( in the SQL statement.

VALUES ('timestamp','$remote) INSTEAD OF VALUES 'timestamp','$remote')

Posted: Fri Nov 01, 2002 9:17 am
by qads
i see 8O ...but it worked on my compter.

thanks :D