[SOLVED] Why does this show an error after the second if sta

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Why does this show an error after the second if statement?

Post by andylyon87 »

Code: Select all

if($save){
if($TheFile="form_data/$_POSTїsave].txt";
         $Open = fopen($TheFile,"w");
         if($Open){
                   fwrite($Open,"$editing\n");
                   fclose($Open);
                   $Worked=True;
          }else{
          $Worked=False;
          }
          return $Worked;
          ){
print("<TR><TD colspan=5><CENTER>file created/updated");
&#125;else&#123;
print("<TR><TD colspan=5><CENTER>Error occured during processing please go back and retry");&#125;
&#125;
the second if statement is not accepted?
I had a workin version but have lost it so need this one to work.
Have made the write to file a separate functon but its to do with the line $TheFile. Please help
thanks
Andy :?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Yeah, that's pretty borked, i think you want something along the lines of:

Code: Select all

<?php
if(!empty($_POST['save'])){
  $TheFile = 'form_data/'.$_POST['save'].'.txt';
  $Open = @fopen($TheFile, 'w');
  if($Open === FALSE){
    $msg = 'Error occured during processing please go back and retry.';
  } else {
    fputs($Open, $editing."\n");
    fclose($Open);
    $msg = 'file created/updated.';
  }
  echo '<tr><td colspan="5" align"center">'.$msg.'</td></tr>';
}
?>
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

so does the !empty correspond to not empty
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

cheers mate works now
Post Reply