physaux Posted October 13, 2009 Share Posted October 13, 2009 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!! Link to comment https://forums.phpfreaks.com/topic/177607-solved-simple-mysql-event-counter-problem-idk-why-its-not-working/ Share on other sites More sharing options...
physaux Posted October 13, 2009 Author Share Posted October 13, 2009 I got it, i had bad syntax. Link to comment https://forums.phpfreaks.com/topic/177607-solved-simple-mysql-event-counter-problem-idk-why-its-not-working/#findComment-936454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.