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
doggy
Forum Commoner
Posts: 80 Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa
Post
by doggy » Sun May 23, 2004 4:30 am
This script is a stats thingy i just wrote but if the entry in the db doesn`t esitst then it adds it but it doesn`t want to update the hits and stuff ( field u , n )
Code: Select all
<?php
include("config.php");
if (isset($_GET['url'])) {
$address = $_GET['url'];
dbi();
$sql = "SELECT * FROM stats WHERE url = '$address'";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) == 1) {
$sql2 = "SELECT * FROM stats WHERE url = '$address'";
$result2 = mysql_query($sql2) or die(mysql_error());
$row2 = mysql_fetch_array($result2);
$u = $row2['u'];
$n = $row2['n'];
if ($u !== $_SERVER['REMOTE_ADDR']) {
$u + 1;
$n + 1;
$sql3 = "UPDATE stats SET u = '$u', n = '$n'";
$result3 = mysql_query($sql3) or die(mysql_error());
} else {
$n + 1;
$sql4 = "UPDATE stats SET u = '$u', n = '$n'";
$result4 = mysql_query($sql4) or die(mysql_error());
}
} else {
$sql5 = "INSERT INTO stats (sid, url, u, n) VALUES (NULL,'$address','1','1')";
$result5 = mysql_query($sql5) or die(mysql_error());
}
}
?>
doggy
Forum Commoner
Posts: 80 Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa
Post
by doggy » Sun May 23, 2004 5:06 am
Update script but still not working
Code: Select all
<?php
include("config.php");
if (isset($_GET['url'])) {
$address = $_GET['url'];
dbi();
$sql = "SELECT * FROM stats WHERE url = '$address'";
$result = mysql_query($sql) or die(mysql_error());
echo mysql_num_rows($result);
if (mysql_num_rows($result) > 0) {
$sql2 = "SELECT * FROM stats WHERE url = '$address'";
$result2 = mysql_query($sql2) or die(mysql_error());
$row2 = mysql_fetch_array($result2);
$u = $row2['u'];
$n = $row2['n'];
$ut = $row2['ut'];
if ($ut == $_SERVER['REMOTE_ADDR']) {
$n + 1;
$sql4 = "UPDATE stats SET n = '$n' WHERE address = '$address'";
$result4 = mysql_query($sql4) or die(mysql_error());
} else {
$user = $_SERVER['REMOTE_ADDR'];
$u + 1;
$n + 1;
$sql3 = "UPDATE stats SET u = '$u', n = '$n', ut = '$user' WHERE address = '$address'";
$result3 = mysql_query($sql3) or die(mysql_error());
}
} else {
$sql5 = "INSERT INTO stats (sid, url, u, n) VALUES (NULL,'$address','1','1')";
$result5 = mysql_query($sql5) or die(mysql_error());
}
}
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Sun May 23, 2004 5:14 am
is it intended to increment $u ?
If so, then correct syntax is:
doggy
Forum Commoner
Posts: 80 Joined: Tue Dec 09, 2003 5:01 am
Location: South Africa
Post
by doggy » Sun May 23, 2004 5:31 am
Thanks that did the trick ,
Thanks dude