Jump to content

PHP Parse error: syntax error, unexpected T_VARIABLE


Go to solution Solved by phpnewbieca,

Recommended Posts

This is the only error I get.

 

PHP Parse error:  syntax error, unexpected T_VARIABLE  on line 15 

 

Line 14: $myfile = "s_vcs.txt"

Line 15: $fh = fopen($myfile, “a+”) or die("Couldn't open $myfile");

 

Help!

 

What is wrong with the coding in line 15?

:confused:  :confused:  :confused:

Sorry, when I copied line 14 I missed the semicolon.

 

I changed $fp to $handle, still not working.

Now, I get this error:

 

PHP Notice:  Use of undefined constant †- assumed 'â€'

line 15 

 

Line 15: $handle = fopen($myfile, “a+”) or die("Couldn't open $myfile");

 <?php
  // Process repair_upgradeform.html 
  error_reporting(-1);
  // Create Random Number 
  srand((double) microtime() * 1000000);
  //Define Variable(s)
  $random_number = rand();
  $confirmation_number = "$random_number";
  $date = date("D  d M Y - H:i:s ");
  $order_date = date("D  d M Y");
  $SendTo = "coon-a@gmx.com";
  $From = "coon-a@gmx.com";
  $error_message = "";
  $myfile = "s_vcs.txt";
  $handle = fopen($myfile, “a+”) or die("Couldn't open $myfile");
  //Get Data From Form
  $Eighteen = $_POST['Eighteen'];
  $List = $_POST['List'];
  $Dsn = $_POST['Dsn']; 
  $Title = $_POST['Title'];
  $Fname = $_POST['Fname'];
  $Lname = $_POST['Lname'];
  $Suffix = $_POST['Suffix'];
  $Address = $_POST['Address'];
  $CityState = $_POST['CityState'];
  $Zip = $_POST['Zip'];
  $Email = $_POST['Email'];
  $Phone = $_POST['Phone']; 
  $Phone_2 = $_POST['Phone_2']; 
  $TypeComputer = $_POST['TypeComputer'];
  $ComputerBrand = $_POST['ComputerBrand'];
  $ComputerModel = $_POST['ComputerModel'];
  if(isset($_POST['Cd'])) {
   $Cd = $_POST['Cd'];
  }
  if(isset($_POST['Cd_rw'])) {
   $Cd_rw = $_POST['Cd_rw'];
  }
  if(isset($_POST['Dvd'])) {
   $Dvd = $_POST['Dvd'];
  }
  if(isset($_POST['Dvd_rw'])) {
   $Dvd_rw = $_POST['Dvd_rw'];
  }
  if(isset($_POST['GraphicCard'])) {
   $GraphicCard = $_POST['GraphicCard'];
  }
  if(isset($_POST['Memory'])) {
   $Memory = $_POST['Memory'];
  }
  if(isset($_POST['Modem'])) {
   $Modem = $_POST['Modem'];
  }
  if(isset($_POST['Multimedia'])) {
   $Multimedia = $_POST['Multimedia'];
  }
  if(isset($_POST['NetworkCard'])) {
   $NetworkCard = $_POST['NetworkCard'];
  }
  if(isset($_POST['Software'])) {
   $SoundCard = $_POST['Software'];
  }
  if(isset($_POST['SoundCard'])) {
   $SoundCard = $_POST['SoundCard'];
  }
  if(isset($_POST['Speakers'])) {
   $Speakers = $_POST['Speakers'];
  }
  $Comments = $_POST['Comments'];
  $FnameUc = ucfirst($Fname);  
  $LnameUc = ucfirst($Lname); 
  $order_num = "$order_date-$LnameUc-$confirmation_number"; 
  // validate expected data exists and is in the correct format ($Fname, $Lname, $Email and $Phone)
  if(!isset($_POST['Eighteen'])) {
   echo "No Age Verification.";
   die();
  }
  if(!isset($_POST['List'])) {
   echo "No Type Service.";
   die();
  }
  if(!isset($_POST['Dsn'])) {
   echo "No Date Service Needed.";
   die();
  }
  if(!isset($_POST['Fname'])) {
   echo "No First Name.";
   died();
  }
  if(!isset($_POST['Lname'])) {
   echo "No Last Name.";
   died();
  }
  if(!isset($_POST['CityState'])) {
   echo "No City\State.";
   die();
  }
  if(!isset($_POST['Email'])) {
   echo "No Email address.";
   die();
  }
  if (check_email_address($Email)) { 
   //echo $Email . " ";
  } 
  else { 
   echo $Email . " is not a valid email address.";
   die();  
  }
  // Call Functions
  Repair_Upgrade_1();
  //FUNCTIONS 
  function died() {
   global $date, $SendTo, $From, $error_message,  $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address,  $CityState, $Zip, $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory,  $Modem, $Multimedia, $NetworkCard, $Software, $SoundCard, $Speakers, $Comments;
   // your error code can go here
    echo "These errors appear below.\n";
    echo "<br /><br />\n";
    echo "$error_message\n";
    echo "<br /><br />\n";
    echo "Please go back and fix these errors.\n"; 
    echo "<br /><br />\n";
    die();
  }
   $error_message = "";
   $string_exp = "/^[A-Za-z .'-]+$/";
   if(!preg_match($string_exp,$Fname)) {
    $error_message.= 'The First Name you entered does not appear to be valid.<br />';
    die();
   }
   if(!preg_match($string_exp,$Lname)) {
    $error_message.= 'The Last Name you entered does not appear to be valid.<br />';
    die();
   }
   $string_exp = "/^[A-Za-z0-9 !-.,:;?']+$/";
   if(!preg_match($string_exp,$Comments)) {
    $error_message.= 'You used invalid charaters in the comments box.<br />';
   }  
   if(strlen($Comments) < 2) {
    $error_message.= 'The Comments you entered do not appear to be valid.<br />';
   }
   if(strlen($error_message) > 0) {
    die($error_message);
   }
  function clean_string($string) {
   $bad = array("content-type","bcc:","to:","cc:","href");
   return str_replace($bad,"",$string);
  }
  function check_email_address($Email) { 
   // First, we check that there's one @ symbol, and that the lengths are right 
   if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Email)) { 
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    echo "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n"; 
    echo "<br />\n";
    return false; 
   } 
   // Split it into sections to make life easier
   $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]); 
   for ($i = 0; $i < sizeof($local_array); $i++) { 
    if  (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])) { 
     echo "Split it into sections to make life easier\n";
     echo "<br />\n";
     return false; 
    } 
   } 
   if (!ereg("^\[?[0-9\.]+\]?$",$Email_array[1])) { 
    // Check if domain is IP. If not, it should be valid domain name 
    //echo "Check if domain is IP. If not, it should be valid domain name\n"; 
    //echo "<br />\n"; 
    $domain_array = explode(".", $Email_array[1]); 
    if(sizeof($domain_array) < 2) { 
 return false; 
 // Not enough parts to domain 
     echo "Not enough parts to domain\n"; 
     echo "<br />\n"; 
    } 
    for ($i = 0; $i < sizeof($domain_array); $i++) { 
 if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { 
 return false; 
 } 
    } 
    } 
    return true; 
  }
  function Repair_Upgrade_1(){
   // write order to file s_vcs.txt
   global $date,  $myfile, $handle, $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address, $CityState, $Zip,  $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory, $Modem, $Multimedia,  $NetworkCard, $Software, $SoundCard, $Speakers, $Comments;
   $handle = fopen($myfile,"a+") or die("couldn't open $Myfile");
   rewind($fh);
   if(!$handle) {
    die("couldn't open file <i>$myFile</i>");
   }
   else {
    $str = "\r\n";
    $str.= "NEW RECORD\r\n";
    $str.= "Confirmation Number: $confirmation_number\r\n"; 
    $str.= "Order Number: $order_num\r\n";   
    $str.= "Date: $date\r\n"; 
    $str.= "Age verification: Are you 18 years or older? $Eighteen\r\n";
    $str.= "Type Service: $List\r\n";
    $str.= "Date Service Needed: $Dsn\r\n";
    $str.= "Title: $Title\r\n";
    $str.= "First Name: ucfirst($Fname)\r\n";
    $str.= "Last Name: ucfirst($Lname)\r\n"; 
    $str.= "Last Name: $Suffix\r\n";    
    $str.= "Address: $Address\r\n"; 
    $str.= "City, State: $CityState\r\n"; 
    $str.= "Zip Code: $Zip\r\n"; 
    $str.= "Email Address: $Email\r\n"; 
    $str.= "Daytime Phone: $Phone\r\n"; 
    $str.= "Evening Phone: $Phone_2\r\n"; 
    $str.= "Type Computer: $TypeComputer\r\n";
    $str.= "Computer Brand: $ComputerBrand\r\n"; 
    $str.= "Computer Model: $ComputerModel\r\n"; 
    $str.= "Items to $List:\r\n"; 
    if($Cd) { 
     $str.= "CD\r\n"; 
    }
    if($Cd_rw) {
     $str.= "CD RW\r\n"; 
    }
    if($Dvd) {
     $str.= "DVD\r\n"; 
    }
    if($Dvd_rw) {
     $str.= "DVD RW\r\n"; 
    }
    if($GraphicCard) {
     $str.= "Graphic Card\r\n";
    }
    if($Memory) { 
     $str.= "Memory\r\n"; 
    }
    if($Modem) {
     $str.= "Modem\r\n";
    }
    if($Multimedia) {
     $str.= "Multimedia\r\n"; 
    }
    if($NetworkCard) {
     $str.= "Network Card\r\n";
    }
    if($Software) {
     $str.= "Software\r\n"; 
    }
    if($SoundCard) {
     $str.= "Sound Card\r\n"; 
    }
    if($Speakers) {
     $str.= "Speakers\r\n\n"; 
    }
    $str.= "Comments: $Comments\r\n";
    $str.= "END OF RECORD\r\n"; 
    $str.= "\r\n"; 
    fwrite($handle, $str);
   }
   fclose($handle);
  }
 ?>
Edited by phpnewbieca

The file is not opening. This was in my browser  "Couldn't open s_vcs.txt".

The 'a+' should append to a file or create the file.

Neither set of quotes single ' ' or double " 'are working.

I tried both.

I do not know why.

Edited by phpnewbieca

Yes, the text file and the script are in the same directory.

Now I have this PHP notice in addition to the others.

PHP Warning:  fopen(s_vcs.txt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Inappropriate ioctl for device in 

:confused:  :confused:  :confused:

When it rains it pours! 

The host server has PHP 52 on it.

Edited by phpnewbieca

 

$handle = fopen($myfile, “a+”)

 

Those quotation marks look wrong in your code. If you're not using a regular text editor (i.e., *not* a word processor or Notepad), you need to switch to one. If you are using a regular text editor, you may have copied and pasted this code from somewhere using funky quotes and this formatting was saved in your document. Try changing those quotation marks to regular " " or ' '.

  • Solution

The file exist and is readable and writable "The file is writable" "The file is readable". I changed permissions to rwx and it

 worked.

I will mark solved after a few dozen test  :happy-04:  :happy-04:  :happy-04:

 

<?php
 // Process repair_upgradeform.html 
 error_reporting(-1);
 // Create Random Number 
 srand((double) microtime() * 1000000);
 //Define Variable(s)
 $random_number = rand();
 $confirmation_number = "$random_number";
 $date = date("D  d M Y - H:i:s ");
 $order_date = date("D  d M Y");
 $SendTo = "coon-a@gmx.com";
 $From = "coon-a@gmx.com";
 $error_message = "";
 $myfile = "s_vcs.txt";
 if (is_writable($myfile)) {
    echo ' ';
 } else {
    echo 'The file is not writable\n\n';
 }
 if (is_readable($myfile)) {
    echo ' ';
 } else {
    echo 'The file is not readable';
 }
 $handle = fopen($myfile, 'a+') or die("Couldn't open $myfile");
 //Get Data From Form
 $Eighteen = $_POST['Eighteen'];
 $List = $_POST['List'];
 $Dsn = $_POST['Dsn']; 
 $Title = $_POST['Title'];
 $Fname = $_POST['Fname'];
 $Lname = $_POST['Lname'];
 $Suffix = $_POST['Suffix'];
 $Address = $_POST['Address'];
 $CityState = $_POST['CityState'];
 $Zip = $_POST['Zip'];
 $Email = $_POST['Email'];
 $Phone = $_POST['Phone']; 
 $Phone_2 = $_POST['Phone_2']; 
 $TypeComputer = $_POST['TypeComputer'];
 $ComputerBrand = $_POST['ComputerBrand'];
 $ComputerModel = $_POST['ComputerModel'];
 if(isset($_POST['Cd'])) {
  $Cd = $_POST['Cd'];
 }
 if(isset($_POST['Cd_rw'])) {
  $Cd_rw = $_POST['Cd_rw'];
 }
 if(isset($_POST['Dvd'])) {
  $Dvd = $_POST['Dvd'];
 }
 if(isset($_POST['Dvd_rw'])) {
  $Dvd_rw = $_POST['Dvd_rw'];
 }
 if(isset($_POST['GraphicCard'])) {
  $GraphicCard = $_POST['GraphicCard'];
 }
 if(isset($_POST['Memory'])) {
  $Memory = $_POST['Memory'];
 }
 if(isset($_POST['Modem'])) {
  $Modem = $_POST['Modem'];
 }
 if(isset($_POST['Multimedia'])) {
  $Multimedia = $_POST['Multimedia'];
 }
 if(isset($_POST['NetworkCard'])) {
  $NetworkCard = $_POST['NetworkCard'];
 }
 if(isset($_POST['Software'])) {
  $SoundCard = $_POST['Software'];
 }
 if(isset($_POST['SoundCard'])) {
  $SoundCard = $_POST['SoundCard'];
 }
 if(isset($_POST['Speakers'])) {
  $Speakers = $_POST['Speakers'];
 }
 $Comments = $_POST['Comments'];
 $FnameUc = ucfirst($Fname);  
 $LnameUc = ucfirst($Lname); 
 $order_num = "$order_date-$LnameUc-$confirmation_number"; 
 // validate expected data exists and is in the correct format ($Fname, $Lname, $Email and $Phone)
 if(!isset($_POST['Eighteen'])) {
  echo "No Age Verification.";
  die();
 }
 if(!isset($_POST['List'])) {
  echo "No Type Service.";
  die();
 }
 if(!isset($_POST['Dsn'])) {
  echo "No Date Service Needed.";
  die();
 }
 if(!isset($_POST['Fname'])) {
  echo "No First Name.";
  died();
 }
 if(!isset($_POST['Lname'])) {
  echo "No Last Name.";
  died();
 }
 if(!isset($_POST['CityState'])) {
  echo "No City\State.";
  die();
 }
 if(!isset($_POST['Email'])) {
  echo "No Email address.";
  die();
 }
 if (check_email_address($Email)) { 
  //echo $Email . " ";
 } 
 else { 
  echo $Email . " is not a valid email address.";
  die();  
 }
 // Call Functions
 Repair_Upgrade_1();
 //FUNCTIONS 
 function died() {
  global $date, $SendTo, $From, $error_message,  $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address, $CityState, $Zip, $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory, $Modem, $Multimedia, $NetworkCard, $Software, $SoundCard, $Speakers, $Comments;
  // your error code can go here
   echo "These errors appear below.\n";
   echo "<br /><br />\n";
   echo "$error_message\n";
   echo "<br /><br />\n";
   echo "Please go back and fix these errors.\n"; 
   echo "<br /><br />\n";
   die();
 }
  $error_message = "";
  $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$Fname)) {
   $error_message.= 'The First Name you entered does not appear to be valid.<br />';
   die();
  }
  if(!preg_match($string_exp,$Lname)) {
   $error_message.= 'The Last Name you entered does not appear to be valid.<br />';
   die();
  }
  $string_exp = "/^[A-Za-z0-9 !-.,:;?']+$/";
  if(!preg_match($string_exp,$Comments)) {
   $error_message.= 'You used invalid charaters in the comments box.<br />';
  }  
  if(strlen($Comments) < 2) {
   $error_message.= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
   die($error_message);
  }
 function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
 }
 function check_email_address($Email) { 
  // First, we check that there's one @ symbol, and that the lengths are right 
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Email)) { 
   // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
   echo "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n"; 
   echo "<br />\n";
   return false; 
  } 
  // Split it into sections to make life easier
  $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]); 
  for ($i = 0; $i < sizeof($local_array); $i++) { 
   if  (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])) { 
    echo "Split it into sections to make life easier\n";
    echo "<br />\n";
    return false; 
   } 
  } 
  if (!ereg("^\[?[0-9\.]+\]?$",$Email_array[1])) { 
   // Check if domain is IP. If not, it should be valid domain name 
   //echo "Check if domain is IP. If not, it should be valid domain name\n"; 
   //echo "<br />\n"; 
   $domain_array = explode(".", $Email_array[1]); 
   if(sizeof($domain_array) < 2) { 
return false; 
// Not enough parts to domain 
    echo "Not enough parts to domain\n"; 
    echo "<br />\n"; 
   } 
   for ($i = 0; $i < sizeof($domain_array); $i++) { 
if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { 
return false; 
} 
   } 
   } 
   return true; 
 }
 function Repair_Upgrade_1(){
  // write order to file s_vcs.txt
  global $date,  $myfile, $handle, $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address, $CityState, $Zip, $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory, $Modem, $Multimedia, $NetworkCard, $Software, $SoundCard, $Speakers, $Comments;
  $handle = fopen($myfile,"a+") or die("couldn't open $Myfile");
  if(!$handle) {
   die("couldn't open file <i>$myFile</i>");
  }
  else {
   $str = "\r\n";
   $str.= "NEW RECORD\r\n";
   $str.= "Confirmation Number: $confirmation_number\r\n"; 
   $str.= "Order Number: $order_num\r\n";   
   $str.= "Date: $date\r\n"; 
   $str.= "Age verification: Are you 18 years or older? $Eighteen\r\n";
   $str.= "Type Service: $List\r\n";
   $str.= "Date Service Needed: $Dsn\r\n";
   $str.= "Title: $Title\r\n";
   $str.= "First Name: ucfirst($Fname)\r\n";
   $str.= "Last Name: ucfirst($Lname)\r\n"; 
   $str.= "Last Name: $Suffix\r\n";    
   $str.= "Address: $Address\r\n"; 
   $str.= "City, State: $CityState\r\n"; 
   $str.= "Zip Code: $Zip\r\n"; 
   $str.= "Email Address: $Email\r\n"; 
   $str.= "Daytime Phone: $Phone\r\n"; 
   $str.= "Evening Phone: $Phone_2\r\n"; 
   $str.= "Type Computer: $TypeComputer\r\n";
   $str.= "Computer Brand: $ComputerBrand\r\n"; 
   $str.= "Computer Model: $ComputerModel\r\n"; 
   $str.= "Items to $List:\r\n"; 
   if($Cd) { 
    $str.= "CD\r\n"; 
   }
   if($Cd_rw) {
    $str.= "CD RW\r\n"; 
   }
   if($Dvd) {
    $str.= "DVD\r\n"; 
   }
   if($Dvd_rw) {
    $str.= "DVD RW\r\n"; 
   }
   if($GraphicCard) {
    $str.= "Graphic Card\r\n";
   }
   if($Memory) { 
    $str.= "Memory\r\n"; 
   }
   if($Modem) {
    $str.= "Modem\r\n";
   }
   if($Multimedia) {
    $str.= "Multimedia\r\n"; 
   }
   if($NetworkCard) {
    $str.= "Network Card\r\n";
   }
   if($Software) {
    $str.= "Software\r\n"; 
   }
   if($SoundCard) {
    $str.= "Sound Card\r\n"; 
   }
   if($Speakers) {
    $str.= "Speakers\r\n\n"; 
   }
   $str.= "Comments: $Comments\r\n";
   $str.= "END OF RECORD\r\n"; 
   $str.= "\r\n"; 
   fwrite($handle, $str);
  }
  fclose($handle);
 }
?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.