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!
<?php
mysql_query("update $usertable set ip = 0 ")or die(mysql_error());
?>
Still have the same error
Parse error: parse error, unexpected T_STRING in /home/teenvote/public_html/user.php on line 496
Somehow if i remove that entire section of code the script works fine.
It is trying to update the ip address to null after a timeout of 1` hour
it read the ip and adds everything but when it get to the part about null
for the ip add everything goes wrong.
Please don't take this the wrong way, but just posting a complete block of code without any explanation of what it refers to or how it fixes things doesn't really help anyone.
Just as unhelpful, the code you posted won't run. It's littered with basic syntax errors which even the synax-colouring has picked up. I haven't bothered to go through it, but I can see a bunch of quote-related errors.
Can I suggest that when you post a block of code, you run it first to make sure its valid, or at the very least use the [Preview] button on the posting form so you can check it with syntax coloring.
$time = time();
mysql_query("UPDATE $usertable SET ip = '$REMOTE_ADDR' WHERE name = '$name' ");
mysql_query("UPDATE $usertable SET timeout = $time WHERE name = '$name' ");
function usersOnline() {
$query = "SELECT ip, timeout FROM $usertable ";
$result = mysql_query($query) or die(mysql_error());
$numrows = mysql_num_rows($result);
if($numrows == 0) {
echo '<b>no</b> users online';
}
elseif($numrows <= 1) {
echo '<b>' . $numrows . '</b> user online';
}
else {
echo '<b>' . $numrows . '</b> users online';
$result1 = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
$timeout = $rowї'timeout'] + 3600 <= time();
$seconds = 3600;
$timestamp = time();
$result2 = $timestamp - $seconds;
if($timeout) {
mysql_query("UPDATE $usertable SET ip = 0 ") or die(mysql_error());
}
}
}
}
Corrections:
* Missing } after while() statement
* echo '<b>'no'</b>' users online'; generates a parse error
* see if you can work out what was wrong with:
$query = mysql_query("select ip,timeout from $usertable) or die(mysql_error());
$result = mysql_query($query);
* $row['timeout'] rather than $row{['timeout']}
* Have a look at the queries: SQL keywords in uppercase and variables enclosed with ' rather than \" for legibility (or without anything for numbers).
since you've already queried the database using the same SQL query and haven't done anything with the result set except count how many records there are. Using mysql_fetch_assoc() means you only return an associative array. mysql_fetch_array() has both an associative and numerical index.