expected unqualified-id before if

I am trying to use a keypad to take the input of one key to turn a sepicific pin on. I have a total of 4 inputs, so when the person press the right button it will turn the right pin. The issue I am having is: I get "expected unqualified-id before if " . I used the switch and got the same issue. Do you know what I am doing wrong?
Here is the code that I am running:

#include <Keypad.h>
int pirPin = 8;
int NamePin = 9;
int HerePin =10;
int CvnPin = 2;
int OffPin = 11;
const byte ROWS = 3; 
const byte COLS = 3; 
char keys[ROWS][COLS] = 
{
  { 
    '1','2','3'     }
  ,
  { 
    '4','5','6'     }
  ,
  { 
    '7','8','9'     }
  ,

};
byte rowPins [ROWS] = { 
  5, 4, 3};
byte colPins [COLS] = { 
  8, 7, 6 }; 
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  Serial.begin (9600);    
  pinMode(NamePin, OUTPUT);
  pinMode(HerePin, INPUT);   
  pinMode(CvnPin, OUTPUT);
  pinMode(OffPin, INPUT);
}  
void handleKeypress (const char key)
{
  Serial.println (key);
} 
if(key == '1')
{
  digitalWrite(NamePin, LOW);
  delay(1000);
  digitalWrite(NamePin, HIGH);
  delay(1000);

else if (key = '3')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(HerePin, HIGH);
delay(1000);
else if (key = '7')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(CvnPin, HIGH);
delay(1000);
else (key = '9')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(OffPin, HIGH);
delay(1000);
}
void loop()
{
  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);
}
void handleKeypress (const char key)
{
  Serial.println (key);
}  // this curly ends the handleKeypress function definition
if(key == '1')  // the rest of the code up to loop() is not in the function definition
{
  digitalWrite(NamePin, LOW);
  delay(1000);
  digitalWrite(NamePin, HIGH);
  delay(1000);

else if (key = '3')