Solved

Why i cannot use if and else here?

Posted on 2008-06-09
6
181 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 21

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now