Author |
Message |
retro
Junior WebHelper
Joined: 10 Apr 2004
Posts: 5
|
Posted:
Sat Apr 10, 2004 2:54 pm (20 years ago) |
|
I've been trying to code a simple app which will store the date, ip, hostname and referer of the visitor and store it into mysql database.
I've have so many problems with doing this. In the end i decided to start basic and i've coded and very simple one which will only get the hostname, byusing the following code.
Code: |
<?php
$db = mysql_connect("host","username","password");
mysql_select_db("database",$db);
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$query = "INSERT INTO stats(hostname) VALUES('$hostname');
$result = mysql_query($query);
?>
|
This still doesn't work, can someone give me some help or advice?
Regards |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Apr 10, 2004 3:56 pm (20 years ago) |
|
Are the entries in your database empty, or are there none at all? |
________________________________
|
|
|
|
retro
Junior WebHelper
Joined: 10 Apr 2004
Posts: 5
|
Posted:
Sat Apr 10, 2004 4:18 pm (20 years ago) |
|
Nothing at all but also i get an error
Parse error: parse error in stats.php on line 9 |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Apr 10, 2004 4:29 pm (20 years ago) |
|
Here is the problem:
Code: | $query = "INSERT INTO stats(hostname) VALUES('$hostname'); |
Replace that with
Code: | $query = "INSERT INTO stats(hostname) VALUES('$hostname')"; |
|
________________________________
|
|
|
|
retro
Junior WebHelper
Joined: 10 Apr 2004
Posts: 5
|
Posted:
Mon Apr 12, 2004 4:03 pm (20 years ago) |
|
Display the results in the database
Code: |
<?php
$db = mysql_connect("host","user","password");
mysql_select_db("retro",$db);
Print ("Visitor Stats Logfile");
print ("<P><table width=\"100%\" border=\"0\"> <tr> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">Date</font></td> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">IP</font></td> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">Hostname</font></td> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">Referer</font></td></tr>");
$Query2 = "SELECT * from Stats";
$Results = mysql_db_query("retro",$query, $db);
while($Row2 = mysql_fetch_array($Result2)){
print(" <tr> <td width=\"242\"><font size=\"2\"?$Row2[id]</font></td>
<td width=\"242\"><font size=\"2\">$Row2[date]</font></td> <td width=\"242\"><font size=\"2\">$Row2[ip]</font></td>
<td width=\"242\"><font size=\"2\">$Row2[hostname]</font></td> <td width=\"242\"><font size=\"2\">$Row2[referer]</font></td>
</tr>");} print("</table">;
?>
|
Parse error: parse error in /mnt/host-users/r/e/t/viewstats.php on line 15 |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Apr 12, 2004 4:59 pm (20 years ago) |
|
Replace Code: | print(" <tr> <td width=\"242\"><font size=\"2\"?$Row2[id]</font></td>
<td width=\"242\"><font size=\"2\">$Row2[date]</font></td> <td width=\"242\"><font size=\"2\">$Row2[ip]</font></td>
<td width=\"242\"><font size=\"2\">$Row2[hostname]</font></td> <td width=\"242\"><font size=\"2\">$Row2[referer]</font></td>
</tr>"); | with Code: | print(' <tr> <td width="242"><font size="2">' . $Row2[id] . '</font></td>
<td width="242"><font size="2">' . $Row2[date] . '</font></td> <td width="242"><font size="2">' . $Row2[ip] . '</font></td>
<td width="242"><font size="2">' . $Row2[hostname] . '</font></td> <td width="242"><font size="2"> ' . $Row2[referer] . '</font></td>
</tr>'); |
|
________________________________
|
|
|
|
retro
Junior WebHelper
Joined: 10 Apr 2004
Posts: 5
|
Posted:
Tue Apr 13, 2004 3:07 pm (20 years ago) |
|
Still having problems with it
this is the full code as of now:
Code: |
<?php
$db = mysql_connect(host,username,password);
mysql_select_db("retro",$db);
Print ("Visitor Stats Logfile");
print ("<P><table width=\"100%\" border=\"0\"> <tr> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">Date</font></td> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">IP</font></td> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">Hostname</font></td> <td width=\"242\"><p><font face=\"Verdana\" size=\"2\">Referer</font></td></tr>");
$Query2 = "SELECT * from Stats";
$Results = mysql_db_query("retro",$query, $db);
while($Row2 = mysql_fetch_array($Result2))
{
print(' <tr> <td width="242"><font size="2">' . $Row2[id] . '</font></td> <td width="242"><font size="2">' . $Row2[date] . '</font></td> <td width="242"><font size="2">' . $Row2[ip] . '</font></td> <td width="242"><font size="2">' . $Row2[hostname] . '</font></td> <td width="242"><font size="2"> ' . $Row2[referer] . '</font></td> </tr>');
}
print("</table">;
?>
|
|
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue Apr 13, 2004 4:25 pm (20 years ago) |
|
What is the problem now? |
________________________________
|
|
|
|
retro
Junior WebHelper
Joined: 10 Apr 2004
Posts: 5
|
Posted:
Tue Apr 13, 2004 4:45 pm (20 years ago) |
|
still getting 'Parse error' i've looked and looked and cant find anything wrong with it. I think its something to do with the loop, but like i said i cant find anything wong with it. |
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Tue Apr 13, 2004 4:52 pm (20 years ago) |
|
Its this:
print("</table">;
should be:
print("</table>"); |
|
|
|
|
|
Page generation time: 0.131273 seconds :: 18 queries executed :: All Times are GMT
Powered by
phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme