09-19-2012, 12:30 AM
|
#1 (permalink)
|
|
The Wanderer
Join Date: May 2012
Posts: 6
Thanks: 2
|
getting error when put recapatcha in to script! need help
I have a script input that allows you to add to the site guest book, which connects and sends data to the MYSQL data-base. The data base and everything else works fine, if i dont add the reCapatch script everything works perfectly... but then when i add reCapatch i pull out a 500 error, and for the life of me cant figure out why. Could you guys take a look and see if you can spot the problem! i am guessing its not reCapatcha causing the problem but something in my custom code for the data thanks
here is my script:
PHP Code:
<?php
require_once('location/recaptchalib.php');
$privatekey = "my 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 {
// Your code here to handle a successful verification
$dbservertype='mysql';
$servername='sname';
// username and password to log onto db server
$dbusername='uname';
$dbpassword='dbpass';
// name of database
$dbname='dbname';
////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword){
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
$email=$_POST['email'];
$name=$_POST['name'];
$country=$_POST['country'];
$dtl=$_POST['dtl'];
$status = "OK"; // setting the flag for form validation
$msg=""; // error message string is blank
// now let us check email address
if (!stristr($email,"@") OR !stristr($email,".")) {
$msg="<center>Your email address is not correct</center><BR>";
$status="NOT OK";
}
// Now let us check if name is entered or not
if(strlen($name) < 2 ){ // if name is less than two char length
$msg .="<center>Please enter your name</center><BR>";
$status="NOT OK";
}
if($status<>"OK"){ // if form validation is not passed
echo "<BR><BR>";
echo $msg. "<br><center><input type='button' value='Retry' onClick='history.go(-1)'></center><br><br><br>";
}else{
$tm=time(); // reading the time of entry
// adding data to mysql database
//first thing is to escape single quotes!
$dtl = str_replace("'","\'",$dtl);
//now process
$rt=mysql_query("insert into guest_book(name,email,country,tm,dtl) values('$name','$email','$country','$tm','$dtl')");
echo mysql_error();
echo "Thank you for your comment! You will automaticly be redirected...";
//send e mail to self with the users e mail address for a thank you message!
}
header('Refresh: 5; URL=../');
?>
|
|
|
|