2013-12-27 12:23
浏览 129


Hi I am attempting to impliment Recaptcha into my php file to secure a page that allows users to add comments. but I am getting this fatal error: Fatal error: Call to undefined function recaptcha_check_answer() in /home/fh11alb/public_html/home.php on line 30

Does anybody know what I might be doing wrong?

if (!isset($_SESSION['logged'])){
$_SESSION = array();
$_SESSION = destroy();
header('location: home_start.php'); //your login form

$db_hostname = 'xxxx';
$db_database = 'xxxx';  
$db_username = 'xxxx'; 
$db_password = 'xxxx'; 
$db_status = 'not initialised';
$str_result = ' ';
$str_options = ' ';
$db_server = mysqli_connect($db_hostname, $db_username, $db_password);
$db_status = "connected";
$db_select = mysqli_select_db($db_server, $db_database);
if (!$db_server){
die("Unable to connect to MySQL: " . mysqli_connect_error($db_server)); 
$db_status = "not connected";
    if(trim($_POST['submit']) == "Submit") {
              $privatekey = "xxxxx";    
                $resp = recaptcha_check_answer ($privatekey,

         if (!$resp->is_valid) {
                $message = "The reCAPTCHA wasn't entered correctly. Go back and try it again. (reCAPTCHA said: " . $resp->error . ")";
                // Get and clean the input data
                //$bedrooms = clean_string($db_server, $_POST["comments"]) ;
                // create the SQL query
                //$query = "SELECT Bedrooms, Price, Location, Company FROM table2 WHERE Bedrooms LIKE '%$Bedrooms%'";
                //mysqli_select_db($db_server, $db_database);
                //$result = mysqli_query($db_server, $query);
                //if (!$result) die("Database access failed: " . mysqli_error($db_server));
                 // if there are any rows, print out the contents
                //while($row = mysqli_fetch_array($result)) {
                        //$str_result .= $row['Bedrooms'] . " (" .
                                        //$row['Price'] . "), " .
                                        //$row['Location'] . ", who voted " .
                                        //$row['Company'] . " to raising tuition fees.<br />";
                        //if($str_result == "") $str_result = "No data found";
                        //$message = "Your search found the following information<br />:";
                        //Print out existing comment
                        $query = "SELECT * FROM comments";
                        $result = mysqli_query($db_server, $query);
                        if (!$result) die("Database access failed: " . mysqli_error($db_server)); while($row = mysqli_fetch_array($result)){
                        } $str_comments .= "<p>" . $row['comment'] . "</p>";
                        } else {
                            //$str_result = 'No MP was requested';
                            //Get any submitted comments and insert
                            //$comment = clean_string($db_server, $_POST['comment']);
                            if ($comment != '') {
                                    $query = "INSERT INTO comments (comment) VALUES ('$comment')";
                                    mysqli_select_db($db_server, $db_database);
                                    mysqli_query($db_server, $query) or
                                                 die("Insert failed: " . mysqli_error($db_server));
                                    $message = "Thanks for your comment!";

//require_once “db_close.php”;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="home.css" rel="stylesheet" type="text/css"/>

<div id="middle">
<h2>Welcome to <strong>Cosy Cribs</strong> website!</h2>
<p>This website combines all the possible lettings available to YOU from the most prefered letting companies in the great city of Leeds!</p>
<p>It was recognised that when students attempt to let a house for the next year, there were far too many different websites and companies visit; making the whole ordeal of finding a house more stressful then needs be!</p>
<p>We, at <strong>Cosy Cribs</strong>, decided that your lives needed to be made easier, and so we announce a website that provides you with all of the lettings from these different companies - all on one website - and links to the house you like.</p>
<form id="comments" action="home.php" method="post"> <select name="comments">
<h1>Do you have a comment on preferred company or number of bedrooms?</h1>
Comment: <textarea rows="2" cols="30" name="comment"></textarea>

<input type="submit" id="submit" name="submit" value="Submit" />
<?php echo $message;
    echo $str_result;
        $publickey = "xxxxx";
    echo recaptcha_get_html($publickey);
<?php echo $recaptcha_form;   //Close connection!
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhe4608 2013-12-27 12:26

    Your require won't be executed if the condition it is in evaluates to false.

    You should move the require outside of any conditional.

    打赏 评论

相关推荐 更多相似问题