Thank you I got that the Global Variables can not be lower cases thank you… Need to learn more about parsing do you know of a good tutorial about parsing…
Because the curly braces did the job here…
One more thing is not inserting why?
Useronline Insert Failed > 0 users online
?>
the whole code above is working now with all the fixes we have done…
the final draft come to this
//fill in some basic info
$server = "localhost";
$db_user = "username";
$db_pass = "password";
$database = "users";
$timeoutseconds = 300;
DEFINE ('REMOTE_ADDR', $_SERVER['REMOTE_ADDR']);
DEFINE ('PHP_SELF', $_SERVER['PHP_SELF']);
//get the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
//connect to database
mysql_connect($server, $db_user, $db_pass);
//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}'");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
//delete values when they leave
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}
//grab the results
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'");
if(!($result)) {
print "Useronline Select Error > ";
}
//number of rows = the number of people online
$user = mysql_num_rows($result);
//spit out the results
mysql_close();
if($user == 1) {
print("$user Hungry online\
");
} else {
print("$user users online");
}
?>
This is the insertion point:
//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}'");
if(!($insert)) {
print "Useronline Insert Failed > ";
here at the Insert point if mysql_db_query is not true then it will print "Useronline Insert Failed…
Now one of the things I have is that I open an connection in header.php
//fill in some basic info
$server = "localhost";
$db_user = "username";
$db_pass = "password";
$database = "users";
$timeoutseconds = 300;
thenk I include header.php - with a connection to the localhost already- I include it in index.php
Index.php has a connection to the same database as well so now we have two connection I know it is unnecessary having two connection but because of my lack of ability to adapt the tutorial connection to the one i have already i haven’t done it.
$timeoutseconds = 300; variable and it’s numeric value has terrified me to try…
Well I have tried doing this.
Index.php
<?php include("includes/header.php");?>
<?php require_once("includes/connection.php");?>
Remember header.php has a connection pluse the connection.php required in index.php makes it two
The connection.php looks like this.
<?php require("constant.php");
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if(!$connection){
die("Database connection failed:" . mysql_error());
}
mysql_set_charset('utf8',$connection);
$db_select = mysql_select_db(DB_NAME, $connection);
if(!$db_select){
die("Database selection failed: " . mysql_error());
}
Costant.php is
<?php
// Database Constants
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER') ? null : define("DB_USER", "username");
defined('DB_PASS') ? null : define("DB_PASS", "password");
defined('DB_NAME') ? null : define("DB_NAME", "ohr");
?>
Still the connection is failing I don’t know what could be the cause…