Bezoekers statistieken insert/update
Ik heb een script van dit forum gebruikt om de bezoekers gegevens te registreren in MySql.
Ik krijg er gegevens in, dus dat werkt.
Alleen hij update geen gegevens omdat ik die functie niet heb meegegeven.
Nou vermoed ik dat ik de if functie moet gaan gebruiken, maar snap niet hoe ik die constructie in elkaar moet zetten.
Wie wil me even helpen?
Dit is de code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$dbhost = "localhost";
$dbuser = "database";
$dbpass = "password";
$dbname = "database";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
//--- set easy vars!
$ipaddr = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H.i.s');
//--- set languages
$lang['nl'] = "NL";
$lang['us'] = "USA";
$lang['hu'] = "Hungarian";
$lang['de'] = "Germany";
$lang['fr'] = "France";
$lang['be'] = "Belgium";
$lang['au'] = "Australia";
$lang['se'] = "Sweden";
$lang['fi'] = "Finland";
$lang['uk'] = "UK";
//--- get country from hostname!
$hostname = gethostbyaddr($ipaddr);
$hostname_slizes = explode('.', $hostname);
$count_slizes = count($hostname_slizes);
$piece = $count_slizes - 1;
$extention = $hostname_slizes[$piece];
//--- check if country code is defined above
if ($lang[$extention])
$language = $lang[$extention];
else
$language = "Unknown";
//--- set platforms
$agent['windows'] = "Windows";
$agent['mac'] = "Macinotosh";
$agent['linux'] = "Linux";
$agent['unix'] = "Unix";
//-- define user agent
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach($agent as $key => $value)
{
if (preg_match("/" . $key . "/", $user_agent))
$platform = $agent[$key];
}
if (!$platform)
$platform = "Unknown";
//--- echo die sjit!
//echo "<p>Client IP: " . $ipaddr . "<br />";
//echo "Client language: " . $language . "<br />";
//echo "Client platform: " . $platform . "<br />";
//echo "Client time: " . $time . "<br />";
//echo "Client date: " . $date . "</p>";
$insertquery = mysql_query("INSERT INTO `database`.`Statistieken` (`ip` , `Language` , `Platform` , `Time` , `Date`)VALUES ('$ipaddr', '$language', '$platform', '$time', '$date');");
$updatequery = mysql_query("UPDATE INTO `database`.`Statistieken` (`ip` , `Language` , `Platform` , `Time` , `Date`)VALUES ('$ipaddr', '$language', '$platform', '$time', '$date');");
?>
$dbhost = "localhost";
$dbuser = "database";
$dbpass = "password";
$dbname = "database";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
//--- set easy vars!
$ipaddr = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H.i.s');
//--- set languages
$lang['nl'] = "NL";
$lang['us'] = "USA";
$lang['hu'] = "Hungarian";
$lang['de'] = "Germany";
$lang['fr'] = "France";
$lang['be'] = "Belgium";
$lang['au'] = "Australia";
$lang['se'] = "Sweden";
$lang['fi'] = "Finland";
$lang['uk'] = "UK";
//--- get country from hostname!
$hostname = gethostbyaddr($ipaddr);
$hostname_slizes = explode('.', $hostname);
$count_slizes = count($hostname_slizes);
$piece = $count_slizes - 1;
$extention = $hostname_slizes[$piece];
//--- check if country code is defined above
if ($lang[$extention])
$language = $lang[$extention];
else
$language = "Unknown";
//--- set platforms
$agent['windows'] = "Windows";
$agent['mac'] = "Macinotosh";
$agent['linux'] = "Linux";
$agent['unix'] = "Unix";
//-- define user agent
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach($agent as $key => $value)
{
if (preg_match("/" . $key . "/", $user_agent))
$platform = $agent[$key];
}
if (!$platform)
$platform = "Unknown";
//--- echo die sjit!
//echo "<p>Client IP: " . $ipaddr . "<br />";
//echo "Client language: " . $language . "<br />";
//echo "Client platform: " . $platform . "<br />";
//echo "Client time: " . $time . "<br />";
//echo "Client date: " . $date . "</p>";
$insertquery = mysql_query("INSERT INTO `database`.`Statistieken` (`ip` , `Language` , `Platform` , `Time` , `Date`)VALUES ('$ipaddr', '$language', '$platform', '$time', '$date');");
$updatequery = mysql_query("UPDATE INTO `database`.`Statistieken` (`ip` , `Language` , `Platform` , `Time` , `Date`)VALUES ('$ipaddr', '$language', '$platform', '$time', '$date');");
?>
Alvast bedankt voor je hulp.
UPDATE
tabelnaam
SET
gegeven1 = gegeven1,
gegeven2 = gegeven2,
enz enz ...
http://www.w3schools.com/sql/sql_update.asp
Gewijzigd op 01/01/1970 01:00:00 door Erik Rijk
Code (php)
1
2
3
4
5
6
2
3
4
5
6
$updatequery = mysql_query("UPDATE database.Statistieken
SET ip = '".$ipaddr."',
Language = '".$language."',
/* enzovoorts */
WHERE iets = iets");
?>
SET ip = '".$ipaddr."',
Language = '".$language."',
/* enzovoorts */
WHERE iets = iets");
?>
in de where geef je op welke rij hij moet updaten
en gebruik geen ` backtics.
Slechte boel.
Groet,
Barry
Gebruik geen kolom- of tabelnamen met hoofdletters, dat gaat vroeg of laat gegarandeerd verkeerd.
Verder laat je 'database' weg, dit voegt niets toe, ik moet de eerste SQL-query nog tegenkomen die niet voor een database is bestemd...
En vergeet niet om te controleren of de queries wel zijn gelukt, die kunnen ieder ongewenst moment mislukken.
try this:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
//Edited by Mike Stuard @ Wednesday 1 August 2007
$dbhost = "localhost";
$dbuser = "database";
$dbpass = "password";
$dbname = "database";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
//--- set easy vars!
$ipaddr = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H.i.s');
//--- set languages
$lang['nl'] = "NL";
$lang['us'] = "USA";
$lang['hu'] = "Hungarian";
$lang['de'] = "Germany";
$lang['fr'] = "France";
$lang['be'] = "Belgium";
$lang['au'] = "Australia";
$lang['se'] = "Sweden";
$lang['fi'] = "Finland";
$lang['uk'] = "UK";
//--- get country from hostname!
$hostname = gethostbyaddr($ipaddr);
$hostname_slizes = explode('.', $hostname);
$count_slizes = count($hostname_slizes);
$piece = $count_slizes - 1;
$extention = $hostname_slizes[$piece];
//--- check if country code is defined above
if ($lang[$extention]) {
$language = $lang[$extention]; }
else {
$language = "Unknown"; }
//--- set platforms
$agent['windows'] = "Windows";
$agent['mac'] = "Macinotosh";
$agent['linux'] = "Linux";
$agent['unix'] = "Unix";
//-- define user agent
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach($agent as $key => $value)
{
if (preg_match("/" . $key . "/", $user_agent))
$platform = $agent[$key];
}
if (!$platform) {
$platform = "Unknown"; }
// Hier het nieuwe gedeelte voor de update
$query = mysql_query("SELECT Language, Platform FROM database.Statistieken WHERE ip='$ipaddr' OR Platform='$platform'")
or die(mysql_error());
while($object = mysql_fetch_object($query)){
$dblanguage = $object->Language; // check Language
$dbagent = $object->Platform; // check Platform (User Agent)
if (!$language == $dblanguage && !$user_agent == $dbagent) {
$updatequery = mysql_query("UPDATE database.Statistieken SET ip='$ipaddr' AND Platform='$platform' AND Time='$time' AND Date='$date'")
or die(mysql_error()); }
else {
//--- echo die sjit!
echo "<p>Client IP: " . $ipaddr . "<br />";
echo "Client language: " . $language . "<br />";
echo "Client platform: " . $platform . "<br />";
echo "Client time: " . $time . "<br />";
echo "Client date: " . $date . "</p>";
mysql_query("INSERT INTO database.Statistieken (ip,Language,Platform,Time,Date)VALUES ($ipaddr,$language,$platform,$time,$date)")
or die(mysql_error());
}
?>
//Edited by Mike Stuard @ Wednesday 1 August 2007
$dbhost = "localhost";
$dbuser = "database";
$dbpass = "password";
$dbname = "database";
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);
//--- set easy vars!
$ipaddr = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H.i.s');
//--- set languages
$lang['nl'] = "NL";
$lang['us'] = "USA";
$lang['hu'] = "Hungarian";
$lang['de'] = "Germany";
$lang['fr'] = "France";
$lang['be'] = "Belgium";
$lang['au'] = "Australia";
$lang['se'] = "Sweden";
$lang['fi'] = "Finland";
$lang['uk'] = "UK";
//--- get country from hostname!
$hostname = gethostbyaddr($ipaddr);
$hostname_slizes = explode('.', $hostname);
$count_slizes = count($hostname_slizes);
$piece = $count_slizes - 1;
$extention = $hostname_slizes[$piece];
//--- check if country code is defined above
if ($lang[$extention]) {
$language = $lang[$extention]; }
else {
$language = "Unknown"; }
//--- set platforms
$agent['windows'] = "Windows";
$agent['mac'] = "Macinotosh";
$agent['linux'] = "Linux";
$agent['unix'] = "Unix";
//-- define user agent
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
foreach($agent as $key => $value)
{
if (preg_match("/" . $key . "/", $user_agent))
$platform = $agent[$key];
}
if (!$platform) {
$platform = "Unknown"; }
// Hier het nieuwe gedeelte voor de update
$query = mysql_query("SELECT Language, Platform FROM database.Statistieken WHERE ip='$ipaddr' OR Platform='$platform'")
or die(mysql_error());
while($object = mysql_fetch_object($query)){
$dblanguage = $object->Language; // check Language
$dbagent = $object->Platform; // check Platform (User Agent)
if (!$language == $dblanguage && !$user_agent == $dbagent) {
$updatequery = mysql_query("UPDATE database.Statistieken SET ip='$ipaddr' AND Platform='$platform' AND Time='$time' AND Date='$date'")
or die(mysql_error()); }
else {
//--- echo die sjit!
echo "<p>Client IP: " . $ipaddr . "<br />";
echo "Client language: " . $language . "<br />";
echo "Client platform: " . $platform . "<br />";
echo "Client time: " . $time . "<br />";
echo "Client date: " . $date . "</p>";
mysql_query("INSERT INTO database.Statistieken (ip,Language,Platform,Time,Date)VALUES ($ipaddr,$language,$platform,$time,$date)")
or die(mysql_error());
}
?>
Ik heb er een commend bijgezet waar de code is veranderd...
Greetz, Mike ;)
Gewijzigd op 01/01/1970 01:00:00 door Mike
Als eerste kreeg ik de melding dat de code niet werd afgesloten.
Je opent een while maar sluit hem niet af.
Nadat ik dit gecorrigeerd had, krijg ik nu de volgende fout:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.145.160,NL,Windows,16.44.53,01/08/2007)' at line 1
Maar wat moet ik hier nu mee?