Current location: Hot Scripts Forums » Programming Languages » PHP » anybody know where this code has gone wrong?


anybody know where this code has gone wrong?

Reply
  #1 (permalink)  
Old 08-16-05, 02:46 PM
monkey123 monkey123 is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
anybody know where this code has gone wrong?

PHP Code:

<?


$server 
'xxx'//your database host
$db_user 'xxx'//your database username
$db_pass 'xxx'//your database password
$dbname 'xxx'//your database name

/* Database Stuff, do not modify below this line */
$connection mysql_pconnect("$server","$db_user","$db_pass"
    or die (
"Couldn't connect to server.");

$db mysql_select_db("$dbname"$connection)
    or die(
"Couldn't select database.");
    

$table "usersonline"//Table where information is kept
$timeoutseconds 300//Recommended


//Fetch Time
$time time();
$timeout $timestamp $timeoutseconds;
$ip $REMOTE_ADDR;
$domain=$_GET['domain'];

//Insert User
$insert mysql_db_query($dbname"INSERT INTO $table VALUES ('$time','$ip','$domain')") or die("Failed1!");

//Delete User
$delete mysql_db_query($dbname"DELETE FROM $table WHERE timestamp<$timeout") or die("Failed2!");

//Fetch Users Online
$result mysql_db_query($dbname"SELECT DISTINCT ip FROM $table") or die("Failed!3");
$users mysql_num_rows($result);

//spit out the results
if($users == 1) {
print(
"$users User Online!\n");
} else {
print(
"$users Users Online!\n");
}
?>
help me, iv been through it a million time and it still fails on this line.

PHP Code:

$insert mysql_db_query($dbname"INSERT INTO $table VALUES ('$time','$ip','$domain')") or die("Failed1!"); 

__________________
Monkey
Reply With Quote
  #2 (permalink)  
Old 08-16-05, 03:25 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
I think your insert line is incomplete as you are not specifying where to input the values ?

PHP Code:

$insert mysql_db_query($dbname"INSERT INTO $table VALUES ('$time','$ip','$domain')") or die("Failed1!"); 

Should be - altering ( time, ip, domain ) to suite your database column names.

PHP Code:

$insert mysql_db_query($dbname"INSERT INTO $table ( time, ip, domain ) VALUES ('$time','$ip','$domain')") or die("Failed1!"); 

Anthony
Reply With Quote
  #3 (permalink)  
Old 08-17-05, 01:48 AM
Beyonder Beyonder is offline
New Member
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
echo 'this INSERT statement' when program is running.

Paste the statement to here.
Reply With Quote
  #4 (permalink)  
Old 08-17-05, 04:03 AM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
When you say "it still fails on this line", do you mean that PHP crashes, or it displays "failed!" meaning that mysql literally failed the query?
Updating Bonzo's suggestion:
PHP Code:

 $insert mysql_db_query($dbname"INSERT INTO $table ( time, ip, domain ) VALUES ('$time','$ip','$domain')") or die("Failed! <b>Mysql Said:</b><br><br>".mysql_error()); 

Just for debugging purposes, obviously you wouldn't show this extra information on your final site.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with this code? hazarus PHP 6 02-23-05 11:19 PM
Not loading from MySQL database, i dont know whats wrong with the code alfrin PHP 5 02-12-05 03:26 PM
What's wrong with this code? whoknow Visual Basic 3 10-02-04 09:03 PM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 12:10 PM
something wrong with this code superman PHP 3 07-06-03 10:55 PM


All times are GMT -5. The time now is 07:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.