Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Why i cannot use if and else here?

Posted on 2008-06-09
6
184 Views
Last Modified: 2008-06-09
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);
      }
}
}
0
Comment
Question by:firekiller15
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:JesterToo
ID: 21747984
You have an extra "}" at line 12/13
0
 

Author Comment

by:firekiller15
ID: 21748127
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

0
 
LVL 16

Accepted Solution

by:
DrNikon224 earned 250 total points
ID: 21748149
There are double-quotes opened on line 3, but never closed. I think you're missing the tail end of line 3.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:firekiller15
ID: 21748157
that one is typo
ok fix but still have that error message
0
 

Author Comment

by:firekiller15
ID: 21748165
if i get rid of else then no error
why cannot put else here
0
 
LVL 16

Expert Comment

by:DrNikon224
ID: 21748169
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?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question