Spot the parse error?

Hi guys,

I need a huge favour. Cant find whats causing this parse error, would like a fresh set of eyes to take a quick look. Ive check all my include (ie require_once) files and the parse error is deffintly not coming from them. Its been puzzling me for nearly 3hrs now

Thanks in advance !


<?
require_once("conf.inc.php");
require_once("functions.php");
// ---
// register new user
// ---
function register($firstName, $lastName, $street, $suburb, $postcode, $state, $country, $businessAreacode, $businessPh, $mobilePh, $title, $faxAreacode, $faxPh, $company, $website, $emailAddress, $username, $pass, $question, $answer)
{
   GLOBAL $db;
   $firstName = trim($firstName);
   $lastName = trim($lastName);
   $street = trim($street);
   $suburb = trim($suburb);
   $postcode = trim($postcode);
   $state = trim($state);
   $country = trim($country);
   $businessAreacode = trim($businessAreacode);
   $businessPh = trim($businessPh);
   $mobilePh = trim($mobilePh);
   $title = trim($title);
   $faxAreacode = trim($faxAreacode);
   $faxPh = trim($faxPh);
   $company = trim($company);
   $website = trim($website);
   $emailAddress = trim($emailAddress);
     
   $username = trim($username);
   $pass = trim($pass);
   
//	NB: $question = addslashes(trim($question)); is NOT used since magic_quotes_gpc is on, and it will add slashes.
//	I.E. If you were posting "Sir'Weaser" from a form to your script and have magic_quotes_gpc on, then the string is slashed
//already so if you run addslashes() again you will be entering "Sir'Weaser" into MySQL.  In that case "Sir'Weaser"
//	would be the correct output.
  
   $question = trim($question);
   $answer = trim($answer);
   
   //check email address
   $validEmail = valid_email($emailAddress);
   if(!$validEmail)
   {
   		return "error=invalid email";
   }
   //check if user with same username already exists in db
   $check_query = run_query("SELECT username FROM user_auth_tbl");
   if(!$check_query)
   {
   		return "error=unable to verify username";
   }
   else
   {
      if(mysql_num_rows($check_query)>0)
	  {
	  	 return "user=in use";
	  }
   }
   //encode password
   $password = md5(trim($pass));
   
   // all checks OK, now insert user authentication details
    $auth_query = run_query("INSERT INTO user_auth_tbl (user_level, username, password, secret_question, secret_answer, last_login) VALUES "
   ."('$username', '$password', '$question', '$answer')");
   $user_id=mysql_insert_id();//get unique user id from last insert query
  
   if(!$auth_query)
   {
      $status = "error=unable to register user";
   }
   else
   {
   //insert details OK, now insert user contact details
   	  $details_query = run_query("INSERT INTO user_details_tbl (user_id,first_name,last_name,street,suburb,postcode,state,country,company,title,email_address,area_code,business_ph,mobile_ph,fax) VALUES "
   ."($user_id,'$firstName','$lastName','$street','$suburb','$postcode','$country','$title','$company','$email_address',$area_code,$business_ph,$mobile_ph,$fax,now())");
      if(!$details_query)
	  {
	  	$status = "error=unable to register user";
	  }
	  else
	  {
	  	$message="<body bgcolor=#DCE292>Dear $first_name,<br>"
		."&nbsp;&nbsp;&nbsp;&nbsp;Thank you for registering at our website, http://www.in-ex.com.au<br>"
		."You are two steps away from logging in and accessing our Online Gallery.<br><br>"
		."To activate your membership please click on link below:<br>"
		."http://www.in-ex.com.au/activate.php?id=$user_id&code=$db_password<br>"
		."AOL users please cut and past this link into a new browser window:<br>"
		."please click here: http://www.in-ex.com.au/activate.php?id=$user_id&code=$password<br><br>"
		."Once you activate your memebership, you will be able to login<br>"
		."with the following information:<br><br>"		
		."Username: $email_address<br>"
		."Password: $random_password<br><br>"
		."Thanks!<br>"
		."<i>The Webmaster</i><br><br>"
		."<b>This is an automated response, please do not reply!</b></body>";
	  	//send email to email address
		//function send_email($senderName, $senderAddress, $recieverAddress, $subject, $body){
		
		if(send_email("IN-EX-LIVING", "[email protected]", "$email_address", "Your registration", "$message"))
		{
			$status ="user=ok";
		}
		else
		{
			$status ="error=activation email not sent";
		}
		
		
		
	}
	return $status;
}

// ---
// login, check user
// ---
function login($username,$pass)
{
   GLOBAL $db;
   $username = trim($username);
   $password = md5(trim($pass));
   $check_query = run_query("SELECT * FROM user_auth_tbl WHERE username = '$username' AND password = '$password'");
   if(!$check_query)
   {
	  	$status = "error=unable to verify login";
	}
	else
	{
		$row = mysql_fetch_array($check_query);
		if(!$row)
		{
			$status = "user=denied";
		}
		else if($row['activated']=0)
		{
			$status = "user=not activated";
		}
		else
		{
			//update last login date time info
			$update_query = run_query("UPDATE user_auth_tbl SET last_login = now() WHERE username='$username'");
			if(!$update_query)
			{
				$status = "error=unable to update login";
			}
			else
			{
				$status = "user=ok&lastLogin=" . stripslashes($row['last_login']);
			}
		}
	}
	return $status;
}

// ---
// forget password
// ---
function forget($email_address)
{
   GLOBAL $db;
   $email = trim($email);
   $question_query = mysql_query("SELECT user_id, username.user_auth_tbl, secret_question.user_auth_tbl FROM user_auth_tbl AND user_details_tbl  WHERE user_id.user_auth_tbl = user_id.user_details_tbl AND email_address.user_details_tbl = '$email_address'");
   if(!$question_query){
   		$status = "error=" . mysql_error();
	}else{
	   if(mysql_num_rows($question_query)<1)
   		{
      		$status = "error=email not present into database";
   		}else{
			$row = mysql_fetch_array($query);
   			$status = "username=$row[username]&question=" . stripslashes($row['secret_question']);
		}
	}
	return $status;
}

// ---
// generate new password
// ---
function new_password($username,$email_address,$answer)
{
   GLOBAL $db;
   $username = trim($username);
   $email_address = trim($email_address);
   $answer = addslashes(trim($answer));
   $query = mysql_query("SELECT * FROM user_auth_tbl WHERE username = '$username' AND secret_answer = '$answer'");
   if(mysql_num_rows($query) < 1)
   {
      $status = "error=wrong answer";
   }
   else
   {
	   
	   $rand_string = '';
	   // ---
	   // generating a random 8 chars lenght password
	   // ---
	   for($a=0;$a<7;$a++)
	   {
		  do
		  {
			 $newrand = chr(rand(0,256));
		  } while(!eregi("^[a-z0-9]$",$newrand));
		  $rand_string .= $newrand;
	   }
	   $pwd_to_insert = md5($rand_string);
	   $new_query = mysql_query("UPDATE user_auth_tbl SET password = '$pwd_to_insert' WHERE username = '$username'");
	   if(!$new_query)
	   {
		  $status = "error=unable to update value";
	   }
	   $status = "username=$username&new_pass=".stripslashes($rand_string);
	 }
	 return $status;
   //NB: maybe send it to email account instead
}

function activate($id, $code){
//NB: For account activation after registration
	$update_query = mysql_query("UPDATE user_auth_tbl SET activated = 1 WHERE user_id = intval($id) AND password='$code'");
	if(!$update_query)
	{
		$status = "error=unable to update value";
	}
	else
	{
		$status = "activated=yes";
	}
	return $status;
}

// decisional switch

if(isset($HTTP_POST_VARS["action"]))
{

   switch($HTTP_POST_VARS["action"])
   {
  
      case "register":
         $result = register($HTTP_POST_VARS['firstName'], $HTTP_POST_VARS['lastName'],$HTTP_POST_VARS['street'],$HTTP_POST_VARS['suburb'],$HTTP_POST_VARS['postcode'],$HTTP_POST_VARS['state'],$HTTP_POST_VARS['country'],$HTTP_POST_VARS['areaCode'],$HTTP_POST_VARS['businessPh'],$HTTP_POST_VARS['mobilePh'],$HTTP_POST_VARS['title'],$HTTP_POST_VARS['faxAreacode'],$HTTP_POST_VARS['faxPh'],$HTTP_POST_VARS['company'],$HTTP_POST_VARS['website'],$HTTP_POST_VARS['emailAddress'],$HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass'],$HTTP_POST_VARS['question'],$HTTP_POST_VARS['answer']);
         print urlencode($result);
         break;
      case "activate":
         $result = activate($HTTP_POST_VARS['id'], $HTTP_POST_VARS['code']);
         print urlencode($result);
         break;
      case "login":
         $result = login($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass']);
         print urlencode($result);
         break;
      case "forget":
         $result = forget($HTTP_POST_VARS['emailAddress']);
         print urlencode($result);
         break;
      case "new_password":
         $result = new_password($HTTP_POST_VARS['username'],$HTTP_POST_VARS['emailAddress'],$HTTP_POST_VARS['answer']);
         print urlencode($result);
         break;
   }
}
?>

Whoops! Forgot to mention that

yeah its…

Parse error: parse error in /server/www/docs/test/php/user.php on line 256

I ran it through my debugger and got ‘unexpected $end’ on the final line… Not much help huh?

what is line 256?

You’re missing a right curly bracket at the bottom of the register function. If you are more careful with your indentation these types of error will be easier to spot.

A good way to find these type of error is to comment out blocks of code until the error goes away. Then you know the error is in the block of code you’ve commented out. Of course this only works if you only have one error…

Cheers guys,

Biggest prob I had Hans was that I’d been working with the script for too long it was a a blur to me. I think somewhere in b/w changing editors it was formatted …Anyway thanks again