I don't get OUTPUT

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

I don't get OUTPUT

Post by jamal »

Hi Guys,
I have corrected some of the code.
But I don't get any output.
The code did not output anything to the screen.
Please can you help me.
Here are the syntax of mysql code,
#####################################
#CREATE TABLE tracker (
# id int(5) NOT NULL auto_increment,
# browser varchar(50) NOT NULL default '',
# count int(10) NOT NULL default '0',
# date date NOT NULL default '0000-00-00',
# host varchar(50) NOT NULL default '',
# PRIMARY KEY (id)
#) TYPE=MyISAM;
#####################################



Thanks in advanced for your support.
Jam

Code: Select all

<?php
 
$connection = mysql_connect("localhost", "user", "pass") or die("no go bro can not connect"); 
$database = "tracker"; 

$table="tracker"; // this is a tablename

$db = mysql_select_db("$database") or die ("y0 no database"); 
$browser = $HTTP_USER_AGENT; 
$date1 = date("F jS Y, h:iA"); 

$result = mysql_query("SELECT host FROM $table where host LIKE '%$REMOTE_ADDR%'"); 
if (mysql_num_rows ($result) == 1) 
{ 
mysql_query ("UPDATE  $table SET date='$date1'  WHERE host = '$REMOTE_ADDR'"); 
mysql_query ("UPDATE  $table SET count=count+1 WHERE host = '$REMOTE_ADDR'"); 
mysql_close($connection); 
} 

else { 

if ($REMOTE_HOST == "") { 
    $host = $REMOTE_ADDR; 
} else { 
    $host = $REMOTE_HOST; 
} 

if ( empty( $HTTP_REFERER ) or '' == $HTTP_REFERER ) { 
    $HTTP_REFERER = 'No Referer'; 
} 


mysql_query ("INSERT INTO  $table (browser, date, host, referer) VALUES ('$browser','$date1','$host','$HTTP_REFERER' )"); 

mysql_close($connection); 
} 
?>
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

What are you trying to output to the screen?

Your code will only output something if any of the mysql commands fail.
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

Post by jamal »

Hi
These are what I am trying to output to the screen:

$REMOTE_ADDR
REMOTE_HOST
HTTP_REFERER

Thanks for your response.
Jamal
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Looking at your script.. if you want to display the variables straight away then just add this to the end of your code..

Code: Select all

echo("Browser : ".$browser."<br>");
echo("Host : ".$host."<br>");
echo("Referer : ".$HTTP_REFERER."<br>");
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

..also try adding ` ` around your field names like this..

Code: Select all

mysql_query ("INSERT INTO  $table (`browser`, `date`, `host`, `referer`) VALUES ('$browser','$date1','$host','$HTTP_REFERER' )");

..it's a good to start doing that as it lowers the chance of you using a reserved mysql name.
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

Post by jamal »

hi
This may sound boring.
How can I make the first lines of a file the php request for http vars ???

Thanks in Advanced.
Jamal
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I'm not sure what you mean exactly.. but if you are trying to send variables to your PHP from an HTML page (like a form or something) then just link to your PHP page in a similar way to this..

mypage.php?variable_a=bob&variable_b=john

variable_a and variable_b can be any variable names you like.. just add the variable value after each variable with the = sign.. and add more variables using the & sign.

Hope this helps.
Post Reply