Problem with motor driver

I need to control 2 DC motors (12V,300mA(stall)). So I built a motor controller using the L293DNE ic. It controls 1 motor perfectly but when I program the arduino with instructions for the second motor, the 1st motor does not spin in one direction. I have written a code to test the motor in both directions. I have all the ground lines common. I am powering the motors from a pc psu(12V,10A) or a NiCD battery pack(6V). i soldered 0.1uF capacitors across the motor terminals and a 10uF electrolytic capacitor across the motor power supply.

int motor1Pin1 = 3;    // pin 2 on L293D
int motor1Pin2 = 4;    // pin 7 on L293D
int enablePin1 = 9;    // pin 1 on L293D
int motor2Pin1 = 5;    // pin 10 on L293D
int motor2Pin2 = 6;    // pin 15 on L293D
int enablePin2 = 10;    // pin 9 on L293D
void setup() 
{
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enablePin1, OUTPUT);
  pinMode(enablePin2, OUTPUT);
  // set enablePin high so that motors can turn on:
  digitalWrite(enablePin1, HIGH);
  digitalWrite(enablePin2, HIGH);

    digitalWrite(motor1Pin1, LOW); 
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW); 
    digitalWrite(motor2Pin2, LOW);

  Serial.begin(9600);

}
void loop()
 {
  
  while(Serial.available() == 0);
  int val = Serial.read()-'0';
  // if input is '1', motor will turn on one direction:
  if(val == 1)
  {
    digitalWrite(motor1Pin1, LOW);   
    digitalWrite(motor1Pin2, HIGH);  
    digitalWrite(motor2Pin1, LOW);   
    digitalWrite(motor2Pin2, HIGH);  
  }
  // if input is other, motor will turn on opposite direction:
  else {
    digitalWrite(motor1Pin1, HIGH);  
    digitalWrite(motor1Pin2, LOW);   
    digitalWrite(motor2Pin1, HIGH);  
    digitalWrite(motor2Pin2, LOW);   
  }
  delay(200);
}

When I upload this the motor1 starts spinning without any input through the terminal, but when I comment out the lines concerning one motor, the other works fine. I have checked and rechecked every connection with a multimeter but did not find any error :(..

How have you connected each motor to the L293D?

through pins 3 and 6(motor 1), and 11 and 14(motor 2) as described in the data sheet..

Its all sounds correct - not sure what else to check...

I think the ic is not working correctly. When I supply "HIGH" to enable pin1 and enable pin 2, the first motor starts spinning..