I am getting a frustrating error with my PHP Code. I am not using short tags, or anything else that causes this error. I checked the brackets, they are all in place. Can you help me?

<?php
  require_once('recaptchalib.php');
  require_once('config.php');
  $privatekey = CAPTCHA_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
	//Start session
	session_start();
	
	//Include database connection details
	require_once('config.php');
	
	//Array to store validation errors
	$errmsg_arr = array();
	
	//Validation error flag
	$errflag = false;
	$regcode = rand(1000,9999);
	//Connect to mysql server
	$link = mysql_connect($DBHOST, $DBUSERNAME, $DBPASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db($DBNAME);
	if(!$db) {
		die("Unable to select database");
	}
	
	//Function to sanitize values received from the form. Prevents SQL injection
	function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}
	//If there are input validations, redirect back to the registration form
	if($errflag) {
		$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
		session_write_close();
		header("location: register-form.php");
		exit();
	}
$uname = $_POST['Username'];
$pword = $_POST['Password'];
$email = $_POST['Email'];
	//Create INSERT query
	$qry = "INSERT INTO members(Username,Password,Email,Userlevel,activated,activation_key) VALUES('$uname','$pword','$email','1','0','$regcode')";
	$result = @mysql_query($qry);
	//Check whether the query was successful or not
	if($result) {
		$query = mysql_query('SELECT * from Members WHERE Email ="$email"');
		$member = mysql_fetch_assoc($result);
$id = $members['MemberID'];
$regcode = $members['activation_key'];
// multiple recipients
$to = $member['Email'];

// subject
$subject = 'Activate your Pastebin Account';

// message
$message = "Activate your Pastebin Account!\nNow you can activate your account. Go to the link below.</p>\n" . print($_SERVER['HTTP_HOST'] . "/activate.php?id=" . $id . "&code=" . $regcode); "
";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= "To: " . $email . "\r\n";
$headers .= 'From: Pastebin Account Activation' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
		header("location: success.php");
		exit();
	}else {
		die("Query failed");
	}
?>
Member Avatar for diafol

Two things.

I think you are missing a closing brace to

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 {

Also:

'SELECT * from Members WHERE Email ="$email"'

not sure if that'll work, how about:

"SELECT * from Members WHERE Email ='$email'"
commented: He is VERY Helpful +0

Alright, stay here, Imma try it.

Two things.

I think you are missing a closing brace to

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 {

Also:

'SELECT * from Members WHERE Email ="$email"'

not sure if that'll work, how about:

"SELECT * from Members WHERE Email ='$email'"

Thanks! I'll give you some reputation!

Member Avatar for diafol

When it works, mark the thread solved (link below the edit box).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.