Page 1 of 1
Error please help
Posted: Fri Sep 20, 2002 3:00 pm
by anrob
I have no idea why this wont work. ====NEWBIE====
Here is the Error
Parse error: parse error, unexpected T_STRING in /home/teenvote/public_html/user.php on line 496
Here is the Code
Code: Select all
// New stuff -->
//$table_name = "select * from usertable";
$time = time();
mysql_query("update $usertable set ip = "$REMOTE_ADDR" where name = "$name" ");
mysql_query("update $usertable set timeout = $time where name = "$name" ");
// here's the meat.
// be sure to edit the $seconds var. if you want to change the timeout.
// $seconds is currently set to one hour.
function usersOnline() {
$query = mysql_query("select ip,timeout from $usertable) or die(mysql_error());
$result = mysql_query($query);
$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());
}
}
}
Thanks
Posted: Fri Sep 20, 2002 3:07 pm
by JPlush76
is the line number you're getting the error on this statement?
Code: Select all
<?php
mysql_query("update $usertable set ip = "$REMOTE_ADDR" where name = "$name" ");
?>
This Line
Posted: Fri Sep 20, 2002 3:11 pm
by anrob
It is on this line
Code: Select all
mysql_query("update $usertable set ip = "0" ")or die(mysql_error());
Here is the original code, if this helps
Code: Select all
function usersOnline() {
$query = "select ip, timeout from $table_name where ip is not null and timeout is not null";
$result = mysql_query($query);
$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);
while($row = mysql_fetch_array($result1)) {
$timeout = $rowї"timeout"] + 3600 <= time();
$seconds = 3600;
$timestamp = time();
$result2 = $timestamp-$seconds;
if($timeout) {
mysql_query("update $table_name set ip = NULL where timeout < $result2");
}
}
}
By the way thanks for answering so fast.
Posted: Fri Sep 20, 2002 3:21 pm
by JPlush76
try this
Code: Select all
<?php
mysql_query("update $usertable set ip = 0 ")or die(mysql_error());
?>
Posted: Fri Sep 20, 2002 3:28 pm
by anrob
JPlush76 wrote:try this
Code: Select all
<?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.
Thanks
Posted: Sat Sep 21, 2002 9:21 am
by Takuma
Code: Select all
<?php
// New stuff -->
//$table_name = "select * from usertable";
$time = time();
mysql_query("update $usertable set ip = "$REMOTE_ADDR" where name = "$name" ");
mysql_query("update $usertable set timeout = $time where name = "$name" ");
// here's the meat.
// be sure to edit the $seconds var. if you want to change the timeout.
// $seconds is currently set to one hour.
function usersOnline() {
$query = mysql_query("select ip,timeout from $usertable) or die(mysql_error());
$result = mysql_query($query);
$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());
}
}
}
}
?>
Posted: Mon Sep 23, 2002 8:19 am
by jonsyd
Hi Takuma,
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.
Regards, Jonny
Posted: Mon Sep 23, 2002 9:17 am
by jonsyd
Try this:
Code: Select all
$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).
Hope this helps, Jonny
Posted: Mon Sep 23, 2002 9:34 am
by twigletmac
One point to add to jonsyd's pretty comprehensive post:
This line:
Code: Select all
$result1 = mysql_query($query) or die(mysql_error());
can be deleted and
Code: Select all
while($row = mysql_fetch_array($result1)) {
can be changed to
Code: Select all
while($row = mysql_fetch_assoc($result)) {
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.
Mac