Timms
09-18-2012, 04:26 PM
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! thanks
here is my script:
<?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!
?>
<?
$to = "cerris@chulse.co.uk";
$subject = "Comment submission";
$message = $name . "\n\n" . $dtl . "\n\n" . $email;
$from = $email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
//now lets send an e mail to the user and thank them!
$to = $email;
$subject = "We want to thank you!";
$message = "You recently submited a review on www.chulse.co.uk. We want to thank you for taking the time to give us your feedback! it is greatly appriciated. If you have any questions at all please contact me using this e mail address or by using the contact form on the website. http://www.chulse.co.uk \n\n Cerris Hulse.";
$from = "cerris@chulse.co.uk";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
}
header('Refresh: 5; URL=../');
?>
here is my script:
<?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!
?>
<?
$to = "cerris@chulse.co.uk";
$subject = "Comment submission";
$message = $name . "\n\n" . $dtl . "\n\n" . $email;
$from = $email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
//now lets send an e mail to the user and thank them!
$to = $email;
$subject = "We want to thank you!";
$message = "You recently submited a review on www.chulse.co.uk. We want to thank you for taking the time to give us your feedback! it is greatly appriciated. If you have any questions at all please contact me using this e mail address or by using the contact form on the website. http://www.chulse.co.uk \n\n Cerris Hulse.";
$from = "cerris@chulse.co.uk";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
}
header('Refresh: 5; URL=../');
?>