Forum Moderators: coopster
This is the script which is executed when the link is clicked:
error_reporting(E_ALL & ~E_NOTICE);$ip_id = $_GET['ip_id'];
$query = "SELECT * FROM sp_ct WHERE block_id = '$ip_id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$query5 = "UPDATE sp_ct SET spct = 1+'".$row['spct']."' WHERE block_id = '$ip_id'" ;
$result5 = mysql_query($query5) or die("<b>mySQL Error:</b>");
if(!$result5)
{
echo 'Error processing request.';
}
else
{
echo '<B><br /><br /><font size="3">Thank you </font></B><br />
'.$row['spct'].'
';
}
echo'
</table>
$spct is set to zero by default.
Logically, I woulda thunk that the above script would be the only one which could increment the variable as it is the only one which refers to that table. The below script pulls variables from a different table, and an ID field in Table A matches another ID field in Table B.
If anyone has an idea of where I am gone wrong I would be most appreciative.
(the other script)
// filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);$x = split("\.",$find);
$find = (256*256*256*$x[0]) + (256*256*$x[1]) + (256*$x[2]) + ($x[3]);
// search for term
$s = long2ip($sip);
$e = long2ip($eip);
echo'
<body>
<!-- MAIN TABLE BEGIN-->
<table align="left" width="98%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="C1" width="150px" valign="top">
</td>
<td width="530px" valign="top" bgcolor="white">
<!-- EMBEDDED CENTER TABLE -->
<table width="100%" align="center">
<tr>
<td>
<!-- EMBEDDED CENTER SUB-TABLE -->';
if ($searching =="yes")
{
echo'
<table width="100%"><br /><br /><br />
<tr>
<td width="25%"><b>IP Searched For:</b></td>
<td width="75%">'.long2ip($find).'</td>
</tr>
</table>
<!-- END EMBEDDED CENTER SUB-TABLE -->
</td>
</tr>
<tr>
<td>
<!-- EMBEDDED LOWER SUB-TABLE -->';
//If they did not enter a search term we give them an error
if ($find == "")
{
echo'
<table width="100%">
<tr>
<td><center>You forgot to enter a search term</center></td>
</tr>
</table></td>
</tr>
</table>
<!-- END EMBEDDED CENTER TABLE -->
</td>
</tr>
</table>
<!-- END MAIN TABLE -->
</body>
</html>';
exit;
}
$query = "SELECT ips.sip, ips.eip, ips.nic, ips.updated, ips.company_id, company.company_id, company.company, company.address1, company.address2, company.zip, company.contact, company.phone, company.e1, company.e2, company.e_ver, company.notes, company.city_id, city.city_id, city.city, company.state_id, state.state_id, state.state, company.country_id, country.country_id, country.country FROM ips, company, city, country LEFT JOIN state ON company.state_id = state.state_id WHERE company.country_id = country.country_id AND company.city_id = city.city_id AND ips.company_id = company.company_id AND sip < '$find' AND eip > '$find'"; // exactly like this
$data = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // explain what's wrong
// display the results
while($result = mysql_fetch_array( $data ))
{
echo "<br>";
}
// counts the number or results
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
$date=date('D M j Y G:i:s');
$sqlquery = "INSERT INTO todo VALUES('','$find', '$date')";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
echo'
<table width="100%">
<tr>
<td><center>The IP Address you entered was not found in our database. </center></td>
</tr>
</table>';
} else {
}
}
$query = "SELECT ips.ip_id, ips.sip, ips.eip, ips.nic, ips.updated, ips.company_id, company.company_id, company.company, company.notes, company.address1, company.address2, company.zip, company.contact, company.phone, company.e1, company.e2, company.e_ver, company.city_id, city.city_id, city.city, company.state_id, state.state_id, state.state, company.country_id, country.country_id, country.country FROM ips, company, city, country LEFT JOIN state ON company.state_id = state.state_id WHERE company.country_id = country.country_id AND company.city_id = city.city_id AND ips.company_id = company.company_id AND sip < '$find' AND eip > '$find'"; // exactly like this
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo'
<br>
<table width="100%">
<tr>
<td class="selcol1" width="25%"><b>Company:</b></td>
<td class="selcol2" width="75%">'.$row['company'].'</td>
</tr>';
if (!empty($row['address1'])) {
echo '<tr>
<td class="selcol1" valign="top"><b>Address:</b></td>
<td class="selcol2">'.$row['address1'].'</td>
</tr>';
} else {
echo '<tr>
<td class="selcol1" valign="top"><b>Address:</b></td>
<td class="selcol2"></td>
</tr>';
}
if (!empty($row['address2'])) {
echo '<tr>
<td> </td>
<td class="selcol2">'.$row['address2'].'</td>
</tr>';
} else {
}
if (!empty($row['city'])) {
echo '<tr>
<td> </td>
<td class="selcol2">'.$row['city'].'';
} else {
}
if (!empty($row['state'])) {
echo ', '.$row['state'].'';
} else {
}
if (!empty($row['zip'])) {
echo ' '.$row['zip'].'</td>
</tr>';
} else {
}
if (!empty($row['country'])) {
echo '<tr>
<td> </td>
<td class="selcol2">'.$row['country'].'</td>
</tr>';
} else {
}
echo'</td>
</tr>
<tr>
<td class="selcol1"><b>Contact:</b></td>
<td class="selcol2">'.$row['contact'].'</td>
</tr>
<tr>
<td class="selcol1"><b>Phone:</b></td>
<td class="selcol2">'.$row['phone'].'</td>
</tr>
<tr>
<td class="selcol1"><b>Email:</b></td>
<td class="selcol2"><b><font color="red">'.$row['e1'].'</font></b></td>
</tr>
<tr>
<td class="selcol1"><b>Email Verified:</b></td>
<td class="selcol2">'.$row['e_ver'].'</td>
</tr>
<tr>
<td colspan="2"><center><br /><a class="style1" href="ip_rec.php?ip_id='.$row['ip_id'].'"> CLICK </a></td>
</tr>
</table>
I would also echo your Update query to and then paste this in your mysql administration tool, to see if it actually does anything.
What you can do to increment by one is this:
UPDATE sp_ct SET spct = 1+spct WHERE block_id = '$ip_id'"
Also I just realized in your Update query you have single quotes ' around the $row['spct'] so mysql is treating like a string, you need to remove them. But using my Update query above should work just fine for you then you don't need 2 queries to the DB.
$ip_id = $_GET['ip_id'];
$query5 = "UPDATE sp_ct SET spct = 1+spct WHERE block_id = '$ip_id'" ;
$result5 = mysql_query($query5) or die("<b>mySQL Error:</b>");
if(!$result5)
{
echo 'Error processing request.';
}
else
{
echo '<B><br /><br /><font size="3">Thank you </font></B><br />
';
echo $query5;
}
I should note that I went back and clicked the same links as I did yesterday and it incremented by 2 again, but then by only 1 every time after that.. So yesterday's clicks: 2,1,1,1,1
And today's clicks: 2,1,1,1,1
I echoed the query5 and it does show correctly:
UPDATE sp_ct SET spct = 1+spct WHERE block_id = '2121'
(and I will use mysql_real_escape_string once I have this bug worked out! baby steps.. hehe)
What do you mean by:
"Check the $_SERVER["HTTP_USER_AGENT"]"
I've done a bit of Googling for this, and I am not sure how to implement to disallow duplicate link hits.
I tried pasting
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser(null, true);
print_r($browser);
And it errors out at the $browser line.
Warning: get_browser(): browscap ini directive not set.
Does that refer to a PHP.INI entry?
EDIT
Yep :) It does. Fixig that. After looking at a sample $_SERVER['HTTP_USER_AGENT'] I am not sure how to tell if a bot is incrementing.
[edited by: BadGoat at 5:57 pm (utc) on Dec. 12, 2006]
To check if it's the adsense bot, do something like below...
if($_SERVER['HTTP_USER_AGENT'] != "Mediapartners-Google/2.1"){
Update your counters;
}