Jump to content

unexpected T_ELSE errors


JeanieTallis

Recommended Posts

I recieve this error when using the code below;

Parse error: syntax error, unexpected T_ELSE in /home/myveeco/public_html/include/session.php on line 315

 

<?php      /* Email error checking */
      $field = "email";  //Use field name for email
      if(!$subemail || strlen($subemail = trim($subemail)) == 0){
         $form->setError($field, "* Email not entered");
      }
      else{
         /* Check if valid email address */
         $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                 ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                 ."\.([a-z]{2,}){1}$";
         if(!eregi($regex,$subemail)){
            $form->setError($field, "* Email invalid");
         }
         $subemail = stripslashes($subemail);
	 }
	 else{ 
     if($database->emailTaken($subemail)){
            $form->setError($field, "* Email already in use");
         }
  } ?>

 

Line 315 is this "else{" Just above "if($database->emailTaken($subemail)){"

I want it so it checks if an email is entered, then checks if the email is valid, then checks if the email is already in use. If it is in use, it gives en error as shown there, the problem isn't the code itself, its the if and else statements. Don't know how to work it out.

 

Any ideas?

Link to comment
Share on other sites

you can only use else AFTER you have used an "if" or "elseif" statement. You cannot use an "else" after an "else" statement.

That's like saying "Johnny will go the park if it's not raining, or else he will stay home, or else he will go to the mall".  You cannot have an else else.  It makes no sense. Here's an idea (not sure if it will work...)

<?php      
/* Email error checking */
$field = "email";  //Use field name for email
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, "* Email not entered");
}
else{
/* Check if valid email address */
$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$";
if(!eregi($regex,$subemail)){
	$form->setError($field, "* Email invalid");
}
$subemail = stripslashes($subemail);
}
if($database->emailTaken($subemail)){
$form->setError($field, "* Email already in use");
}
?>

Link to comment
Share on other sites

This error now occurs

 

Parse error: syntax error, unexpected '{' in /home/myveeco/public_html/include/database.php on line 131

 

Line 131 =      if(!$subuser || strlen($subuser = trim($subuser)) == 0){

 

The block of code is

<?php    function login($subuser, $subpass, $subremember){
      global $database, $form;  //The database and form object

      /* Username error checking */
      $field = "user";  //Use field name for username
      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
         $form->setError($field, "* Username not entered");
      }
      else{
         /* Check if username is not alphanumeric */
         if(!eregi("^([0-9a-z])*$", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
         }
      } ?>

 

Thanks. (none of these errors use to occur until I tried to put in 'email is being used' part.

Link to comment
Share on other sites

knowing now what you were wanting, I think I fixed it for you:

<?php
function login($subuser, $subpass, $subremember){
global $database, $form;  //The database and form object
/* Username error checking */
$field = "user";  //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
	$form->setError($field, "* Username not entered");
}
/* Check if username is not alphanumeric */
if(!eregi("^([0-9a-z])*$", $subuser)){
	$form->setError($field, "* Username not alphanumeric");
}
if($database->emailTaken($subemail)){
	$form->setError($field, "* Email already in use");
}
}
?>

Link to comment
Share on other sites

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/myveeco/public_html/include/session.php on line 143

 

<?php      $field = "pass";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }
      
      /* Return if form errors exist */
      if($form->num_errors > 0){
         return false;
      }?>

 

Line 143 = $field = "pass";  //Use field name for password

 

Shall I put all the origional code, before I started the email is in use bit, so when it last worked properly, so it'll help figure out where 'email is not in use' should go?

Link to comment
Share on other sites

<?php     

/* Email error checking */

$field = "email";  //Use field name for email

if(!$subemail || strlen($subemail = trim($subemail)) == 0){

$form->setError($field, "* Email not entered");

}

$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$";

if(!eregi($regex,$subemail)){
$form->setError($field, "* Email invalid");
}

$subemail = stripslashes($subemail);
if($database->emailTaken($subemail)){
$form->setError($field, "* Email already in use");
}
      ?>

Link to comment
Share on other sites

I'm not too sure what it would be. I have a guess.

This is the whole register form code in session.php

   function register($subuser, $subpass, $subemail, $sublocation){
      global $database, $form, $mailer;  //The database, form and mailer object
      
      /* Username error checking */
      $field = "user";  //Use field name for username
      if(!$subuser || strlen($subuser = trim($subuser)) == 0){
         $form->setError($field, "* Username not entered");
      }
      else{
         /* Spruce up username, check length */
         $subuser = stripslashes($subuser);
         if(strlen($subuser) < 5){
            $form->setError($field, "* Username below 5 characters");
         }
         else if(strlen($subuser) > 30){
            $form->setError($field, "* Username above 30 characters");
         }
         /* Check if username is not alphanumeric */
         else if(!eregi("^([0-9a-z])+$", $subuser)){
            $form->setError($field, "* Username not alphanumeric");
         }
         /* Check if username is reserved */
         else if(strcasecmp($subuser, GUEST_NAME) == 0){
            $form->setError($field, "* Username reserved word");
         }
         /* Check if username is already in use */
         else if($database->usernameTaken($subuser)){
            $form->setError($field, "* Username already in use");
         }
         /* Check if username is banned */
         else if($database->usernameBanned($subuser)){
            $form->setError($field, "* Username banned");
         }
      }

      /* Password error checking */
      $field = "pass";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }
      else{
         /* Spruce up password and check length*/
         $subpass = stripslashes($subpass);
         if(strlen($subpass) < 4){
            $form->setError($field, "* Password too short");
         }
         /* Check if password is not alphanumeric */
         else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
         }
      }     

/* Email error checking */
      $field = "email";  //Use field name for email
      if(!$subemail || strlen($subemail = trim($subemail)) == 0){
      $form->setError($field, "* Email not entered");

}

      $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
      ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
      ."\.([a-z]{2,}){1}$";

      if(!eregi($regex,$subemail)){
      $form->setError($field, "* Email invalid");
}

      $subemail = stripslashes($subemail);
      if($database->emailTaken($subemail)){
      $form->setError($field, "* Email already in use");
}

I'm not sure if the following code is correct, as its a drop down menu, more than a field. Could you help me out?, and I know where I'd put it though.

 

      $field = "location";

      if(!$sublocation || strlen($sublocation = trim($sublocation)) == 0){

      $form->setError($field, "* Location not selected");

 

Thanks.

 

Link to comment
Share on other sites

Nothing doesn't work yet, I added a location dropdown menu to the register form.

The first option in the menu, is blank, that one cant be chosen, so if it's set as default, error returns 'location not selected'

It needs to be in the whole code I sent, so that it checks for errors basically.

 

This code below

 

      $field = "location";

      if(!$sublocation || strlen($sublocation = trim($sublocation)) == 0){

      $form->setError($field, "* Location not selected");

 

is a textfield error, so if nothings typed in, it recieves the error, I don't know what to do about a dropdown.

Do you understand now?

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.