solenoid program

hi, I am working on writing a program that will open a solenoid when a momentary button is pressed and will stay open for a set amount of time depending on what setting a rotary switch is on. Right now everything works except setting one. Setting one I want the solenoid to stay open for as long as the momentary button is being pressed. Right now when I press the button the solenoid opens, but wont turn off when I release the button. Any help is greatly appreciated. Thanks

const int buttonPin=12;
const int solenoidPin=11;
const int knobSetting1=3;
const int knobSetting2=5;
const int knobSetting3=6;



void setup() {
 pinMode(buttonPin,INPUT_PULLUP);
 pinMode(solenoidPin, OUTPUT); 
 pinMode(knobSetting1, INPUT_PULLUP);
 pinMode(knobSetting2, INPUT_PULLUP);
 pinMode(knobSetting3, INPUT_PULLUP);

 }

void loop(){
  
//setting one. The setting I am having trouble with

if(digitalRead(buttonPin)==LOW)//if the button is pressed
if(digitalRead(knobSetting1)==LOW)//If the rotary switch is on setting one
{
digitalWrite(solenoidPin,HIGH);//solenoid open
}

else if (digitalRead(buttonPin!=LOW))
{
delay(10);
digitalWrite(solenoidPin,LOW);//solenoid closed
}

//setting two
if (digitalRead(buttonPin)==LOW)//if the button is pressed
if(digitalRead(knobSetting2)==LOW)//if the rotary switch is on position two

{
  digitalWrite(solenoidPin,HIGH);//solenoid open
  delay(3000);//solenoid open for 3sec
  digitalWrite(solenoidPin,LOW);//solenoid closed
}


if (digitalRead(buttonPin)==LOW)//if the button is pressed
if(digitalRead(knobSetting3)==LOW)//if the rotary switch is in position three

{
  digitalWrite(solenoidPin,HIGH);//open solenoid
  delay(6000);//keep solenoid open for 6sec
  digitalWrite(solenoidPin,LOW);//close solenoid
  }
}
  if (digitalRead(buttonPin) == LOW) //if the button is pressed
    if (digitalRead(knobSetting1) == LOW) //If the rotary switch is on setting one
    {
      digitalWrite(solenoidPin, HIGH); //solenoid open
    }

    else if (digitalRead(buttonPin != LOW))
    {
      delay(10);
      digitalWrite(solenoidPin, LOW); //solenoid closed
    }

Maybe add a few pairs of { and }; they don't cost much. Which if does the else if belong to? If properly indented (as above), it belongs the second if ahnd hence can never be true.

Note
Use tools -> auto format in the IDE to proeprly indent; it makes it easier to spot errors.

Sterretje, thanks for the tips. I started learning about coding and microcontrollers in general a couple months ago and definitely have more to learn. The else if needs to go with
if (digitalRead(buttonPin) == LOW)
How do i pair it to that if and not the
if (digitalRead(knobSetting1) == LOW)? Thanks!

By using { and }.

  if (digitalRead(buttonPin) == LOW) //if the button is pressed
  {
    if (digitalRead(knobSetting1) == LOW) //If the rotary switch is on setting one
    {
      digitalWrite(solenoidPin, HIGH); //solenoid open
    }
  }
  else if (digitalRead(buttonPin != LOW))
  {
    delay(10);
    digitalWrite(solenoidPin, LOW); //solenoid closed
  }

In this situation you also don't need the second if (digitalRead(buttonPin != LOW)); a digitalRead either gives a HIGH or a LOW, there is no third/fourth/... possible value for which you might have wanted the else if.

Which brings the code to

  if (digitalRead(buttonPin) == LOW) //if the button is pressed
  {
    if (digitalRead(knobSetting1) == LOW) //If the rotary switch is on setting one
    {
      digitalWrite(solenoidPin, HIGH); //solenoid open
    }
  }
  else
  {
    delay(10);
    digitalWrite(solenoidPin, LOW); //solenoid closed
  }

Great! I will try that out and see if it works. Thanks again!