Jump to content

Need help with if, elseif and else statements..


pappakaka

Recommended Posts

I can't get these two if, elseif and else statements too work, here is the code:

    if(empty($this->password)){
      $this->errors[] = 'You must enter a password!';
  }
elseif(!strlen($this->password) >= 6){
  $this->errors[] = 'Your password must be longer than 6 characters!';
  }

    if(empty($this->email)){
      $this->errors[] = 'You must enter an email address!';
  }
elseif(!preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/',$this->email)){
  $this->errors[] = 'Your password can only contain these characters: a-z, A-Z and 0-9!';
  }

if(empty($this->confemail)){
      $this->errors[] = 'Please confirm your email address!';
  }
elseif(!$this->confemail == $this->email){
  $this->errors[] = 'The email addresses you entered did not match!';
  }

 

The if and elseif statements for "email" work just fine but the other 2 doesn't.

 

With the "password" i first want to check if the field is empty, and when it is, it works as it should. But when i for example type "test" too check if the password is longer than 6 characters i don't get any message at all?

 

With the "confemail" i want to first check if the field is empty, and when it is, it works as it should. But when i type in "[email protected]" in both fields to try to compare "confemail" to "email" i still get the "Please confirm your email address!" message?

 

Hi pappakaka,

Try changing your conditional operators like this:

elseif(!strlen($this->password) >= 6)

to

elseif (strlen($this->password) < 6)

 

and

elseif(!$this->confemail == $this->email)

to

elseif ($this->confemail != $this->email)

 

cheers,

Fergal

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.