| | |
PHP Error on line
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 1
hello all i am new to this forum and need some help whit php.
I am trying to create a script that shows the number of users online.
My problem is : Parse error: parse error in C:\wamp\www\Untitled-2.php on line 24
My line 24 is this
This is my usersOnline.class.php
Can any one tell me where my prob is?
I am trying to create a script that shows the number of users online.
PHP Syntax (Toggle Plain Text)
<?php $host = "xx.xxx.xxx.xx"; $user = "xxxx"; $pass = "xxxx"; $db = "users" $conn = mysql_connect("$host", "$user", "$pass") or die ("Unable to connect to database."); mysql_select_db("$db", $conn); include_once ("usersOnline.class.php"); $visitors_online = new usersOnline(); if (count($visitors_online->error) == 0) { if ($visitors_online->count_users() == 1) { echo "There is " . $visitors_online->count_users() . " visitor online"; } else { echo "There are " . $visitors_online->count_users() . " visitors online"; } } else { echo "<b>Users online class errors:</b><br /><ul>\r\n"; for ($i = 0; $i < count($visitors_online->error); $i ++ ) { echo "<li>" . $visitors_online->error[$i] . "</li>\r\n"; } echo "</ul>\r\n"; } ?>
My line 24 is this
PHP Syntax (Toggle Plain Text)
$conn = mysql_connect("$host", "$user", "$pass") or die ("Unable to connect to database."); mysql_select_db("$db", $conn);
This is my usersOnline.class.php
PHP Syntax (Toggle Plain Text)
class usersOnline { var $timeout = 600; var $count = 0; var $error; var $i = 0; function usersOnline () { $this->timestamp = time(); $this->ip = $this->ipCheck(); $this->new_user(); $this->delete_user(); $this->count_users(); } function ipCheck() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } function new_user() { $insert = mysql_query ("INSERT INTO useronline(timestamp, ip) VALUES ('$this->timestamp', '$this->ip')"); if (!$insert) { $this->error[$this->i] = "Unable to record new visitor\r\n"; $this->i ++; } } function delete_user() { $delete = mysql_query ("DELETE FROM useronline WHERE timestamp < ($this->timestamp - $this->timeout)"); if (!$delete) { $this->error[$this->i] = "Unable to delete visitors"; $this->i ++; } } function count_users() { if (count($this->error) == 0) { $count = mysql_num_rows ( mysql_query("SELECT DISTINCT ip FROM useronline")); return $count; } } } ?>
-1
#2 Oct 31st, 2009
I haven't looked closely at your code, but it looks as though you've left out a semicolon at the end of:
PHP Syntax (Toggle Plain Text)
$db = "users"
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
-1
#4 Oct 31st, 2009
@above.
if your script is work and ur problem is solved then please mark this thread to solve.
if your script is work and ur problem is solved then please mark this thread to solve.
http://www.kuchamancity.com
Hem Web Solution..
Behind Every Successful Man, There is an Untold Pain in His Heart.
Hem Web Solution..
Behind Every Successful Man, There is an Untold Pain in His Heart.
•
•
Join Date: Oct 2009
Posts: 9
Reputation:
Solved Threads: 1
0
#5 Nov 1st, 2009
Now that i got the number of users on work i have another prob...
I am going to show the total number of registerd users(userID,user name,E-Mail)...and i dont now what this is :
"Notice: Undefined index: id in C:\wamp\www\Untitled-1.php on line 3"
The script works but thet line is buging me
this is line 3
This is the script :
I am going to show the total number of registerd users(userID,user name,E-Mail)...and i dont now what this is :
"Notice: Undefined index: id in C:\wamp\www\Untitled-1.php on line 3"
The script works but thet line is buging me

this is line 3
PHP Syntax (Toggle Plain Text)
$myID = $_GET['id'];
This is the script :
PHP Syntax (Toggle Plain Text)
<?php $myID = $_GET['id']; $server = 'host'; $username = 'dbuser'; $password = 'dbpass'; $database = 'db'; $connect = mysql_connect($server, $username, $password) or die("Error connecting: " . mysql_error()); $select = mysql_select_db($database, $connect) or die("Error selecting DB: " . mysql_error()); // Select a specific entry if(strlen($myID) > 0) { $query = "SELECT * FROM users WHERE id='$myID'"; } // Select EVERY entry else { $query = "SELECT * FROM users"; } ?> <center> <table border='1' cellspacing='0' cellpadding='2'> <tr> <th>ID</th> <th>Nume Utilizator</th> <th>E-Mail</th> </tr> <?php $run = mysql_query($query) or die("Error running query: " . mysql_error()); while($row = mysql_fetch_array($run)) { print("\n<tr><td>{$row['ID']}</td>"); print("\n<td>{$row['username']}</td>"); print("\n<td>{$row['email']}</td></tr>"); } ?> </table> </center>
Last edited by foxwizzy; Nov 1st, 2009 at 5:43 am.
-1
#6 Nov 1st, 2009
Why is it bugging you?
You don't have any validation:
If expecting an integer, you should check to see that you are getting an integer. What happens if an id is not passed? You script will fail. What should you do in this case? Select a random id from the DB or show an error message before redirecting to another page?
Look up:
is_int() and isset()
You don't have any validation:
If expecting an integer, you should check to see that you are getting an integer. What happens if an id is not passed? You script will fail. What should you do in this case? Select a random id from the DB or show an error message before redirecting to another page?
Look up:
is_int() and isset()
Last edited by ardav; Nov 1st, 2009 at 6:09 am.
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
![]() |
Other Threads in the PHP Forum
- Previous Thread: preg_replace Youtube links (regex)
- Next Thread: Problem with Function in Araay
Views: 318 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date development directory display download dynamic echo email error file files folder form forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






