Jump to content

How a counter of users ? such as ---> (231 Viewing)


co.ador

Recommended Posts

I have taken out the or die (mysql_erro))); function now after that it says that mysql_query function has slupplied argument is not a valid mysql link resource line 65, it means that mysql is not compatible with the way we have code the query at line 65

 

Line 65 below!..

 

$insert = mysql_query($database, "INSERT INTO useronline VALUES
('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}'"); 

 

The $database variable right? then the argument would be after the INSERT INTÖ right?

 

what is wrong then?

 

maybe the ['REMOTE_ADDR']} should be lower case?

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\nyhungry\includes\header.php on line 65

Useronline Insert Failed >

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\nyhungry\includes\header.php on line 72

Useronline Delete Failed >

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\nyhungry\includes\header.php on line 78

Useronline Select Error >

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\nyhungry\includes\header.php on line 84

remove $database from mysql_query(), leave just the SQL syntax.

 

keep uppercase at all times when using $_SERVER requests.

Link to comment
Share on other sites

i have the connection alright i think

 

Here is the mysql_connect

 

Connection.php

 <?php require("constant.php");
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if(!$connection){
die("Database connection failed:" . mysql_error());
}
code]

Thenk the mysql_select_db function

[code]mysql_set_charset('utf8',$connection);
$db_select = mysql_select_db(DB_NAME, $connection);
if(!$db_select){
die("Database selection failed: " . mysql_error());
}
[/

 

then the mysql_query functions which are three

 

$insert = mysql_query( "INSERT INTO useronline VALUES
('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}'" . mysql_error()); 
if(!($insert)) { 
print "Useronline Insert Failed > " ; 
} 


//delete values when they leave
$delete = mysql_query("DELETE FROM useronline WHERE timestamp<$timeout" . mysql_error()); 
if(!($delete)) { 
print "Useronline Delete Failed > "; 
} 

//grab the results
$result = mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'" . mysql_error()); 
if(!($result)) { 
print "Useronline Select Error > "; 
}

 

The constant.php file on top in the connection.php goes as fallow maybe is not well set up but, it is working for other pages i don't see why it shouldn't work for this.

 

 

constant.php

<?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", "pass");
defined('DB_NAME')   ? null : define("DB_NAME", "colo");

?>

 

 

i took $database out of there, Now since I am linking connection.php to header.php now instead of $database it should be $connection because that's how i name it in connection.php which is the file that set up the connection to the database.

 

Failing to connect to the database still persisting

 

 

Useronline Insert Failed > Useronline Delete Failed > Useronline Select Error >

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\nyhungry\includes\header.php on line 76

 

the sql database as in the tutorial is as below

 

 

CREATE TABLE useronline (

  timestamp int(15) DEFAULT '0' NOT NULL,

  ip varchar(40) NOT NULL,

  file varchar(100) NOT NULL,

  PRIMARY KEY (timestamp),

  KEY ip (ip),

  KEY file (file)

);

 

but in mysql some how I don konw how to put

KEY ip (ip)

KEY file (file)

 

but the actual database dump I have in phpmyadmin is as:

 

CREATE TABLE IF NOT EXISTS `useronline` (

  `timestamp` int(15) NOT NULL,

  `IP` varchar(40) NOT NULL,

  `file` varchar(100) NOT NULL,

  PRIMARY KEY (`timestamp`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

How can I re-do the database so it contain:

 

KEY ip (ip)

KEY file (file)

 

 

That could be one of the issues.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.