phpnewbieca Posted August 2, 2013 Share Posted August 2, 2013 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? Quote Link to comment Share on other sites More sharing options...
Pawan_Agarwal Posted August 2, 2013 Share Posted August 2, 2013 Line 14: $myfile = "s_vcs.txt"; Line 15: $fh = fopen($myfile, “a+”) or die("Couldn't open $myfile"); write semi-colon in line 14 at the end and it will work........... Quote Link to comment Share on other sites More sharing options...
phpnewbieca Posted August 2, 2013 Author Share Posted August 2, 2013 (edited) 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 August 2, 2013 by phpnewbieca Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 2, 2013 Share Posted August 2, 2013 I think the double quotes are not corrrect. Try, $handle = fopen($myfile, 'a+') or die("Couldn't open $myfile"); OR $handle = fopen($myfile, "a+") or die("Couldn't open $myfile"); Quote Link to comment Share on other sites More sharing options...
phpnewbieca Posted August 2, 2013 Author Share Posted August 2, 2013 (edited) 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 August 2, 2013 by phpnewbieca Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 2, 2013 Share Posted August 2, 2013 Does the text and scripting files are located on the same directory? Quote Link to comment Share on other sites More sharing options...
phpnewbieca Posted August 2, 2013 Author Share Posted August 2, 2013 (edited) 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 When it rains it pours! The host server has PHP 52 on it. Edited August 2, 2013 by phpnewbieca Quote Link to comment Share on other sites More sharing options...
boompa Posted August 2, 2013 Share Posted August 2, 2013 $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 ' '. Quote Link to comment Share on other sites More sharing options...
phpnewbieca Posted August 3, 2013 Author Share Posted August 3, 2013 I'm using Notepad ++ as my editor Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 3, 2013 Share Posted August 3, 2013 Check if the file exist and also it's readle and writable. Quote Link to comment Share on other sites More sharing options...
Solution phpnewbieca Posted August 3, 2013 Author Solution Share Posted August 3, 2013 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 <?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); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.