Jump to content

[SOLVED] Simple MYSQL Event Counter-problem idk why its not working


physaux

Recommended Posts

Hey guys, i am having some problems with this code.

I want to count in a table how many times an IP or EMAIL refreshes my captcha, you know, to detect if it is being botted or whatever. Anyways, i have the following code:

 

What i do is

<?php 
echo requestcaptcha($currentemail);
?>

And the mothod that is called is the following:

<?php
function requestcaptcha($email){//NOT WORKING WITH DATABASE..?
global $connection;
global $ip;
$result = mysql_query("SELECT * FROM captchabyemail", $connection);
if (!$result)
	die("Database query failed: " . mysql_error());
$setyet=false;
while ($row = mysql_fetch_array($result)) {
	if($row["email"] == $email){
		$setyet=true;
		$temp= $row["num"]+1;
		$result = mysql_query("DELETE FROM captchabyemail WHERE email = '".$email."'");
		if (!$result)
			die("Database query failed: " . mysql_error());
		$result = mysql_query("INSERT INTO captchabyemail VALUES('".$email."', '".$temp."'");
		if (!$result)
			die("Database query failed: " . mysql_error());
	}
}
if(setyet==false){
	$result = mysql_query("INSERT INTO captchabyemail VALUES('".$email."', '1'");
		 if (!$result)
	die("Database query failed: " . mysql_error());
}
$result = mysql_query("SELECT * FROM captchabyip", $connection);
if (!$result)
	die("Database query failed: " . mysql_error());
$setyet=false;
while ($row = mysql_fetch_array($result)) {
	if($row["ip"] == $ip){
		$setyet=true;
		$temp= $row["num"]+1;
		$result = mysql_query("DELETE FROM captchabyip WHERE ip = '".$ip."'");
		if (!$result)
			die("Database query failed: " . mysql_error());
		$result = mysql_query("INSERT INTO captchabyip VALUES('".$ip."', '".$temp."'");
		if (!$result)
			die("Database query failed: " . mysql_error());
	}
}
if(setyet==false){
	$result = mysql_query("INSERT INTO captchabyip VALUES('".$ip."', '1'");	
	if (!$result)
		die("Database query failed: " . mysql_error());
}
return '
<img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" />'.linkbackwithsetemail($email, urlencode("New Captcha")).'<br />
Security Code: <input type="text" name="security_code" /><br />';
}
?>

 

Anyways everthing works fine, there are no errors, but when i look into my database after refreshing my captcha alot, nothing ever gets added!

Anyone see any problems? Thanks!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.