Link to home
Start Free TrialLog in
Avatar of firekiller15
firekiller15

asked on

Why i cannot use if and else here?

PHP
i wonder how i can use if and else statement in the code below
if i use if-else in code below i received an error message


$data1 = $data1 = "$datas | {$this->arrayAddressReturn_value[$i]} | $this->GetFileNameReturn"


if ($StudentPull == 0)  {//get file from config.php
switch($this->GetstudentID[$i])  //to get student id from other function
{
  case 1: $fn = $file1; break;
  case 2: $fn = $file2; break;
}

file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
}
}

else
{
foreach($this->GetFileNameReturn as $FileName) //get file from database
      {
 switch($this->GetstudentID[$i])
{
  case 1: $fn = $FileName; break;
  case 2: $fn = $FileName; break;
  case 3: $fn = $FileName; break;
// default:$fn = UNKNOWN; break;
}

file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
      }
}
}
Avatar of JesterToo
JesterToo
Flag of United States of America image

You have an extra "}" at line 12/13
Avatar of firekiller15
firekiller15

ASKER

how about this
i received this error
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\test.php on line 531
foreach($array as $i=> $datas)
{
$data1 = "$datas | {$this->arrayaddressReturn_value[$i]} | 
 
if ($UniversePull)  
 {
switch($this->GetUniverseID[$i])
  {
 case 1: $fn = $file1; break;
 case 2: $fn = $file2; break;
 case 3: $fn = $file3; break;
 default:$fn = $file4; break;
  }
 
file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
 }
 
else
 {
foreach($this->GetFileNameReturn as $FileName)
  {
 switch($this->GetUniverseID[$i])
   {
  case 1: $fn = $FileName; break;
  case 2: $fn = $FileName; break;
  case 3: $fn = $FileName; break;
   }
 
file_put_contents('c:\\'.$fn.'.txt',$data1 , FILE_APPEND);
  }
 }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GarbsTheTurtle
GarbsTheTurtle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that one is typo
ok fix but still have that error message
if i get rid of else then no error
why cannot put else here
Which line of the code you posted is the line 531 referenced in the error? Can you post your typo-fixed code, marked with a comment at line 531?