why would't this work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

why would't this work?

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$query = "INSERT INTO q_useronline VALUES 'timestamp','$remote')";
$insert = mysql_query($query) or die($query.' :'.mysql_error());
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post 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')
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

i see 8O ...but it worked on my compter.

thanks :D
Post Reply