3 Replies - 725 Views - Last Post: 01 June 2012 - 06:24 AM Rate Topic: -----

#1 Eluway  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 29-June 11

syntax error, unexpected T_ELSE: need fresh eyes

Posted 01 June 2012 - 04:59 AM

Hey, so I'm debugging this code and currently getting the following error:

Parse error: syntax error, unexpected T_ELSE in /home/fallenpeopleadmin/keepingitkinky.net/review/verify_book.php on line 61

I can't seem to find any short/extra "{" brackets. I have been looking at the code for the past few days and still haven't found the error. I think I've been looking at it too long and need some fresh eyes.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
	<title>Kinky - Add Book Review</title>
	<meta http-equiv="Content-Language" content="en-us" />
	
	<meta http-equiv="imagetoolbar" content="no" />
	<meta name="MSSmartTagsPreventParsing" content="true" />
	
	<meta name="description" content="Adding a book review" />
	<meta name="keywords" content="" />
	
	<meta name="author" content="" />
	
	<style type="text/css" media="all">@import "../css/style.css";</style>  <style type="text/css" media="all">@import "../css/style.css";</style>
<?php 

 require_once('recaptchalib.php');
  $privatekey = "my_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 {
		//Include database connection details
		include('config.php');

		//Connect to mysql server
		$mysql = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
			if(!$mysql) {
			die('Failed to connect to server: ' . mysql_error());
			} 
	mysql_select_db("my_database", $mysql) or die( "Unable to select database" .  mysql_error());
	}

// Add new book review

$category_array = $_POST['category'];
foreach ($category_array as $one_category) {
$source .= $one_category.", ";
}
$category = substr($source, 0, -2);

if (!empty($_POST['question'])) 
	{ //make sure input exists
	$i=0;
	$j=0;
	for($i < count($_POST['question']); $j++;)/> 
		{ 												   //removes questions with score of '0'
		$score = array_sum($_POST['question']) / ($j * 5); //generates percentage
		$score1 = ($score * 100) / 20; 					   //turns percentage into score out of 5
		$star = number_format($score1, 1);
		}  	
		else {
		$star = 0;
		}
	}

	$insListing_sql = "INSERT INTO book (id, image, rater_name, rate_date, title, author_last, author_first, star, publish_date, publisher, isbn, back_summary, rater_summary, rater_comments, category, buy) VALUES( '', 
			'".mysql_real_escape_string($_POST["image"])."',
			'".mysql_real_escape_string($_POST["rater_name"])."',
			'".mysql_real_escape_string($_POST["rate_date"])."',
			'".mysql_real_escape_string($_POST["title"])."',
			'".mysql_real_escape_string($_POST["author_last"])."',
			'".mysql_real_escape_string($_POST["author_first"])."',
			'".mysql_real_escape_string("$star")."',
			'".mysql_real_escape_string($_POST["publish_date"])."',
			'".mysql_real_escape_string($_POST["publisher"])."',
			'".mysql_real_escape_string($_POST["isbn"])."',
			'".mysql_real_escape_string($_POST["back_summary"])."',
			'".mysql_real_escape_string($_POST["rater_summary"])."',
			'".mysql_real_escape_string($_POST["rater_comments"])."',
			'".mysql_real_escape_string("$category")."',
			'".mysql_real_escape_string($_POST["buy"])."'
			)"; 
	$insListing_res = mysql_query($insListing_sql, $mysql)
			or die(mysql_error($mysql));
 
?>
<table width=70%><tr><td>
<center><h1>Book Review Added!</h1><p>

<a class="ex1" href="book_add.php">Add Another Book Review</a><p>

<?php 
echo "$quest, $score $score1, $star";
?>



Is This A Good Question/Topic? 0
  • +

Replies To: syntax error, unexpected T_ELSE: need fresh eyes

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3524
  • View blog
  • Posts: 10,169
  • Joined: 08-June 10

Re: syntax error, unexpected T_ELSE: need fresh eyes

Posted 01 June 2012 - 05:02 AM

for() doesn’t come with else, if() does.
Was This Post Helpful? 0
  • +
  • -

#3 Eluway  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 29-June 11

Re: syntax error, unexpected T_ELSE: need fresh eyes

Posted 01 June 2012 - 05:08 AM

the for() is nested within an if() statement. I'm not used to writing a lot of loops, just getting into it, can I not nest a for within an if else?
Was This Post Helpful? 0
  • +
  • -

#4 Buzzer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-December 11

Re: syntax error, unexpected T_ELSE: need fresh eyes

Posted 01 June 2012 - 06:24 AM

Hay Eluway,

You seems to place braces at wrong places, after your for() loop you need to close your if statement then move to else statement. The problem is you are writing all code into if statement.

View PostEluway, on 01 June 2012 - 05:08 AM, said:

can I not nest a for within an if else?


and as per above question concern, you CAN write nested for within in if else statement. Just watch out your braces when you write code.

Best of Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1