i have just started using php, i wanted a hit counter that stored all of the
information in a database. i searched around a bit and managed to find this
code :

<html>
<head>
<title>Testing...</title>
</head>
<?
## before using this code you must make the following table in your
database
#Table name: stats
# fields:
Ipaddress(varchar(150)),host(varchar(150)),browser(varchar(150)),referer(var
char(150)),filename(varchar(150)).
# table name: hits
# fields: ipaddress(varchar(150)),count(int(11))
###############################################
global $dblink,$PHP_SELF;
$ip = getenv("REMOTE_ADDR");
$host = getenv("HTTP_HOST");
$browser = getenv("HTTP_USER_AGENT");
$referer = getenv("HTTP_REFERER");
$sql = "SELECT ipaddress FROM stats WHERE ipaddress = '$ip'";
$database = "db/stats.mdb"

$result = @mysql_query($sql, $dblink);
$num = mysql_num_rows($result);
if( $num == 0 )
{
$sql ="INSERT INTO stats(ipaddress,host,browser,referer,filename)
VALUES('$ip', '$host', '$browser', '$referer','$PHP_SELF')";
$result=mysql_query($sql,$dblink);
$sql1="INSERT INTO hits(ipaddress,count) VALUES('$ip',1)";
$result1=@mysql_query($sql1,$dblink);
$text="you had a new visitor from IP: $ip, Host: $host Browser:
$browser Referer: $referer";
if ($result)
{
mail("counter@ponkware.co.uk", "You had a new visitor",$text, "FROM:
hitcounter");
}
}else{
$sql = "UPDATE hits SET count = count + 1 where ipaddress='$ip'";
$result =@mysql_query($sql, $dblink) ;
$sql2 = "UPDATE stats SET filename ='$PHP_SELF' where ipaddress='$ip'";
$result2 =@mysql_query($sql2, $dblink) ;
}
?>
</html>


in the code it tells me i need to make a connection to my database, but i
don't know how to do this, also i'm not sure but i don't think the code
should be in an html file.

could someone tell me what is wrong and how to connect, please reply by
e-mail because i am at college and i will have forgotten about here by the
time i get home.

thanks...