Troubleshooting Buzzer Delay

int variable = 0;
void setup() {
  // put your setup code here, to run once:
  pinMode(A1, INPUT);  //Photocell
  pinMode(12, OUTPUT);  //Led voltage
  pinMode(6, OUTPUT);  //Buzzer (PWM 
  float val;


}

void loop() {
  // put your main code here, to run repeatedly:


  float val = analogRead(A1);
  if (val < 300) {           // if it gets dark out
    digitalWrite(12, 1);   // LED turns on
    digitalWrite(6, 0);    // buzzer remains off
    variable = 1;
    delay(1000);
  }
  else {                         // if its bright outside
    digitalWrite(12, 0);   // LED turns off
    if (variable = 1) {
      analogWrite(6, 10);    // buzzer PWM turns on
      delay(1000);           // wait a second
      digitalWrite(6, 0);    // buzzer pin turns off
      variable = 0;
    }

  }

}

Hey guys,
I am trying to use an input photocell voltage to control the output of an LED and a buzzer. The LED sub circuit works well, but the buzzer is not working properly. I want to have it buzz for one second, however once it turns on it does not turn off until val < 300 again. How can I fix the problem? Thank you in advance.

    if (variable = 1)Whoops !

= for assignment
== for comparison