rocky48 Posted February 27, 2014 Share Posted February 27, 2014 (edited) I am trying to implement reCaptcha on my website but I am having problems since I added the extra coding for reCaptcha. reCaptcha is working OK, but it is not running the code after checking the correct reCaptcha code is correct. I believe that it is because of the else. It does not error and only shows the logo and footer. Here is the code: <?php require_once ('recaptchalib.php'); include("connect_mailer.php"); $privatekey = "Private Key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { //determine if they need to see the form or not if (!$_POST) { //they need to see the form, so create form block $display_block = " <form method=\"POST\" action=\"manage.php\"> <p><strong>Your E-Mail Address:</strong><br/> <input type=\"text\" name=\"email\" size=\"40\" maxlength=\"150\"><br/> <p>Forename</p> <input type=\"text\" name=\"Forename\" size=\"40\" maxlength=\"150\"><br/> <p>Surname</p> <input type=\"text\" name=\"Surname\" size=\"40\" maxlength=\"150\"><br/> <p>Country</p> <input type=\"text\" name=\"Country\" size=\"40\" maxlength=\"150\"><br/> <p>Gender</p> <input type=\"text\" name=\"Gender\" size=\"5\" maxlength=\"150\"> <p><strong>Enter M or F</strong><br/> <p><strong>Action:</strong><br/> <input type=\"radio\" name=\"action\" value=\"sub\" checked> subscribe <input type=\"radio\" name=\"action\" value=\"unsub\"> unsubscribe <p><input type=\"submit\" name=\"submit\" value=\"Submit Form\"></p> </form>"; } else if (($_POST) && ($_POST["action"] == "sub")) { //trying to subscribe; validate email address if ($_POST["email"] == "") { header("Location: manage.php"); exit; } else { //connect to database doDB5(); //check that email is in list emailChecker($_POST["email"]); //get number of results and do action if (mysqli_num_rows($check_res) < 1) { //free result mysqli_free_result($check_res); //add record $add_sql = "INSERT INTO subscribers (email, Forename, Surname, Country, Gender) VALUES('".$_POST["email"]."', '".$_POST["Forename"]."', '".$_POST["Surname"]."', '".$_POST["Country"]."', '".$_POST["Gender"]."')"; $add_res = mysqli_query($mysqli, $add_sql) or die(mysqli_error($mysqli)); $display_block = "<p>Thanks for signing up!</p>"; //close connection to MySQL mysqli_close($mysqli); } else { //print failure message $display_block = "<p>You're already subscribed!</p>"; } } } else if (($_POST) && ($_POST["action"] == "unsub")) { //trying to unsubscribe; validate email address if ($_POST["email"] == "") { header("Location: manage.php"); exit; } else { //connect to database doDB5(); //check that email is in list emailChecker($_POST["email"]); //get number of results and do action if (mysqli_num_rows($check_res) < 1) { //free result mysqli_free_result($check_res); //print failure message $display_block = "<p>Couldn't find your address!</p> <p>No action was taken.</p>"; } else { //get value of ID from result while ($row = mysqli_fetch_array($check_res)) { $id = $row["id"]; } //unsubscribe the address $del_sql = "DELETE FROM subscribers WHERE id = '".$id."'"; $del_res = mysqli_query($mysqli, $del_sql) or die(mysqli_error($mysqli)); $display_block = "<P>You're unsubscribed!</p>"; } mysqli_close($mysqli); } } } ?> <!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Home</title> <link rel="stylesheet" href="style.css" /> </head> <body> <div id="fb-root"> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> </div> <div id="wrapper"> <div id="menu"> <ul> <li class="current_page_item"><a href="index.php">Home</a></li> <li><a href="Links.html">Links</a></li> <li><a href="Verse_Menu.html">Verses</a></li> <li><a href="Techniques.html">Techniques</a></li> <li><a href="blog.php">Blog</a></li> <li><a href="Gallery.html">Gallery</a></li> <li><a href="contact.html">Contact</a></li> <li><a href="AboutUs.html">About Us</a></li> </ul> </div><!-- end #menu --> <div id="header"> <div id="logo"> <h1><a href="http://www.1066cards4U.co.uk">1066 Cards 4U</a></h1> </div> </div><!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <h2>Subscribe/Unsubscribe to Mailing List</h2> <?php echo "$display_block"; ?> <div id="footer"> <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p> <p>Copyright (c) 2013 - 1066 Cards 4U - content and design</p> </div><!-- end #footer --> </body> </html> I am a relatively new programmer so do not understand where it is going wrong. Please can someone help? Edited February 27, 2014 by rocky48 Quote Link to comment https://forums.phpfreaks.com/topic/286579-since-adding-recaptcha-code-not-working/ Share on other sites More sharing options...
rocky48 Posted May 30, 2014 Author Share Posted May 30, 2014 Solved Quote Link to comment https://forums.phpfreaks.com/topic/286579-since-adding-recaptcha-code-not-working/#findComment-1481431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.