?
Solved

Why i cannot use if and else here?

Posted on 2008-06-09
6
Medium Priority
?
187 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
[X]
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
  • 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 1000 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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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