Jump to content

phpnewbieca

Members
  • Posts

    71
  • Joined

  • Last visited

Everything posted by phpnewbieca

  1. I appreciate you taking the time to point out 'readily' identifiable errors. Thank you.
  2. Psycho, I really appreciate the advice you gave me about php programming. Please read my Responses. Some other feedback: 1. You are using GLOBAL in a function - don't! It is a bad practice. Instead, pass the variables to the function that it needs. You are creating a lot of them, so rather than pass each variable as individual values, create the data in an array then simple pass the array to the function. I changed this: function use_form_data() { global var1, var2, var3, etc. To this: function use_form_data($form_data) { //### Define variables echo "Subject ".$form_data [0]; echo "Name ".$form_data [1]." ".$form_data [2]." ".$form_data [3]." ".$form_data [4] ."etc\r\n"; } 2. Give your variables and functions meaningful names. test2_1() doesn't tell you anything about what that function does. Yes, as you are actively working on it you know what id does, but when you need others to help you with code or when you need to go back to code that is even a day or two old you have to relearn what they are. See '2.' above 3. You are trying to enforce business rules that you should not. For example, you are forcing the names to start with an uppercase character and the remaining letters to be lower case. There are many names where this would be invalid: "De La Hoya", "da Vinci", etc. You are right, of course, so I changed the code to this: if(isset($_POST["fname"]) && !empty ($_POST["fname"])) { $Lname = trim($_POST["fname"]); if(preg_match("/[^a-zA-Z]*$/",$fname)){ } else { echo"<strong>The First Name you entered is not valid.</strong>"; echo "<br />\n"; } if(empty($_POST["fname"])) { echo"<strong>You didn't enter a First Name.</strong>"; echo "<br />\n"; } } Note: I don't there is any way to, completely, prevent a user from putting garbage in input fields i.e. xxx xxx would pass the validation. Also: What preg_match validation matches the following U.S. street address: 123 Main St. 123 Main St 123 Main Street 123 NW Main 123 Main St. North 123 Main St., Apt. 4 123 Main St., Suite 456 if(isset($_POST["address"]) && !empty ($_POST["adresss"])) { $address = trim($_POST["address"]); * * * My Guess is * * * if(preg_match("/([0-9]+)\s([a-zAZ]+)(,\s|\s)([a-zAZ]+)(,\s|\s)([a-zAZ]+)(,\s|\s)([a-zAZ0-9]+)*$/",$address)){ * * * Am I right? * * * } else { echo"<strong>The address you entered is not valid.</strong>"; echo "<br />\n"; } if(empty($_POST["address"])) { echo"<strong>You didn't enter a address.</strong>"; echo "<br />\n"; } } 4. You have some 'validations' that have holes. E.g. !empty ($_POST["Lname"]) If the user just enters one or more spaces it will pass this validation. Additionally, values such as "0" or "FALSE" would cause that function to return the same as an empty string. For a name that might be fine, but in other contexts the string "false" or a "0" (zero) may be legitimate values. Instead, you should first trim() the value before checking to see if a value was passed. See '3.' above. 5. There are conditions with no handling of the false results. E.g. if(isset($_POST["Lname"]) && !empty ($_POST["Lname"])) { $Lname = $_POST["Lname"]; if(preg_match("/[^a-zA-Z]*$/",$Lname)){ //### Upper Case First Letter of Last Name $LnameUc = ucfirst($Lname); } else { echo"<strong>The Last Name you entered is not valid.</strong>". PHP_EOL; echo "<br />\n"; exit; } } What happens if $_POST["Lname"] is empty or if it is empty? There is no error handling and the code will go continue on and possibly fail when it tries to reference $LnameUc See '3.' above. 6. Error handling should not require an exit() function and it should not stop checking for errors on the first error encountered. You should try to provide the user with as many of the error conditions as possible. For example, if they are inserting a new record, check for the possible date entry errors on each piece of data (required fields, format, data type (e.g. numbers), etc.) and store the errors into an array. Then after all the validations are complete, if there are any errors, provide them to the user and complete the page. If there are no errors then attempt the next stage in the process, such as inserting the record. If there are errors at that point then show that error and complete the page. There's nothing more frustrating then submitting a form to be told a piece of data needs to be corrected, resubmitting and then being told a different piece of data was also invalid - but not mentioned previously. Huh? Example please.
  3. Mac_gyver, Your analysis of the problem and the solution solved the problem. Thank you. Phycho, Thank you for providing me with a through Analysis of the problem areas of my code. I'M sure it will put me one step closer to obtaining my goal of becoming a 'php Guru'.
  4. Mac_gyver, I have removed the indentation from the heredoc per: $message = <<<EOF EOF; I will test it and share the results of the test Thank you.
  5. test2.php function test2_2() { global $Date, $Appointment_number, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test2 - ". $Test_number."\n\n"; //### begin of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> You have received an Test, <b>that needs to be confirmed.</b> <br> Date Received: <b>$Date</b> <br><br> The information submitted is below: <br> <b>$Title $FnameUc $LnameUc $Suffix</b> <br> <b>$Address</b> <br> <b>$CityState $Zip</b> <br> <b>$mailto</b> <br><br> Comments: <br> <b>$Comments</b> <br><br> Please click the <b><u>Confirm Appointment</u></b> ,below, to confirm the Appointment Date and Time. <br><br> <a href="http://www.mydomain.com/Test3.php?date=$Date&test_number=$Test_number&title=$Title&fname=$FnameUc&lname=$LnameUc&suffix=$Suffix&address=$Address&citystate=$CityState&zip=$Zip&email=$Email&comments=$Comments"> Confirm Appointment - $Test_number</a> <br> </body> </html> EOF; //###end of message $headers = "Mime-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From:" . $From . "\r\n"; $headers .= "Reply-To:" . $From . "\r\n"; $headers .= "Return-Path:" . $From . "\r\n"; $headers .= 'BCC: me@mydomain.net'."\r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; //### Now lets send the email if(mail($mailto, $subject, $message, $headers)){ echo "<b> <font color='green' size='+2'> Confirm Appointment email sent to: ". $mailto."</b></font>"; echo "<br /> <br />"; } else { echo "<b> <font color='red' size='+2'> Confirm Appointment email not sent.</b></font>"; echo "<br /> <br />"; } ==> Line 114 }
  6. One day my hope is to be a PHP 'Guru' but until that day arrives I must read and filter responses from Guru's like you. Who forget that before they 'earned' the title 'Guru' they were noobs/newbies that made mistakes coding and needed help too. Is the missing closing brace for function test2_2() on line 114? Thanks for responding.
  7. Help Please! I'm trying to pass variables in a URL and use them in a HTML email. When test1.php calls Test2.php, test2.php should send two HTML emails but nothing happens. I get this error for test2.php: [24-Feb-2016 16:20:42 UTC] PHP Parse error: syntax error, unexpected end of file in /home/my/public_html/test2.php on line 114 HTML - call test1.php <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="utf8" /> <title>Testform.html</title> </head> <body bgcolor="tan" text ="black"> <form action="test1.php" method="POST" > <table> <tr> <th> ~ Test ~ <br /> </th> </tr> </table> <br /> <table> <tr> <td> * </td> <td> <strong> Required Fields </strong> </td> <tr> </table> <table> <tr> <td> <strong>Title: </strong> </td> <td> <select name="Title" size="1" > <option value="" selected>Please Choose</option> <option value="Mr."> Mr.</option> <option value="Ms."> Ms.</option> <option value="Mrs."> Mrs.</option> </select> </td> </tr> <tr> <td> <strong> First Name: </strong> </td> <td> <input type="text" name="Fname" maxlength="30" /> </td> </tr> <tr> <td> <strong> Last Name: </strong> </td> <td> <input type="text" name="Lname" maxlength="30" /> </td> </tr> <tr> <td> <strong> Suffix: </strong> </td> <td> <select name="Suffix" size="1"> <option value=""> Please Choose </option> <option value="Sr."> Sr.</option> <option value="Jr."> Jr.</option> <option value="III"> III</option> <option value="IV"> IV</option> <option value="V, "> V</option> </select> </td> </tr> <tr> <td> <strong> Address: </strong> </td> <td> <input type="text" name="Address" maxlength=40 /> </td> </tr> <tr> <td> <strong> City, State: </strong> </td> <td> <select name="CityState"> <option value=""> Please Choose </option> <option value="Hometown, CA"> Hometown, CA</option> <option value="My City, CA"> My City, CA</option> <option value="Beautiful, CA"> Beautiful, CA</option> </select> </td> </tr> <tr> <td> <strong> Zip Code: </strong> </font> </td> <td class="td2"> <input type="text" name="Zip" placeholder="99999" maxlength=10 /> </td> </tr> </table> <table> <tr> <th> <strong> Comments: </strong> </th> </tr> </table> <table> <tr> <td> <textarea rows="8" cols="60" name="Comments" wrap="hard"> </textarea> </td> </tr> </table> <table> <tr> <td> <input id="shiny" type="submit" value="Submit Form" /> </td> </tr> </table> </form> </body> </html> TEST1.PHP <?php //###Process testform.html //### Error Reporting error_reporting(E_ALL); //### Create Random Number srand((double) microtime() * 1000000); //### Define Variable(s) $random_number = rand(); $Test_number = "$random_number"; $Date = date("D d M Y - H:i:s "); $path = "/home/mypath/public_html/"; $myfile = "test1.txt"; $file = $path.$myfile; $fh = fopen($file, "a+") or die("Couldn't open $myfile"); //### Get Data From Form if ($_SERVER["REQUEST_METHOD"] === "POST") { if(isset($_POST["Title"])) { $Title = $_POST["Title"]; } if(isset($_POST["Fname"]) && !empty ($_POST["Fname"])) { $Fname = $_POST["Fname"]; if(preg_match("/[^a-zA-Z]*$/",$Fname)){ //### Upper Case First Letter of First Name $FnameUc = ucfirst($Fname); } else { echo"<strong>The First Name you entered is not valid.</strong>". PHP_EOL; echo "<br />\n"; exit; } } if(isset($_POST["Lname"]) && !empty ($_POST["Lname"])) { $Lname = $_POST["Lname"]; if(preg_match("/[^a-zA-Z]*$/",$Lname)){ //### Upper Case First Letter of Last Name $LnameUc = ucfirst($Lname); } else { echo"<strong>The Last Name you entered is not valid.</strong>". PHP_EOL; echo "<br />\n"; exit; } } if(isset($_POST["Suffix"]) && !empty ($_POST["Suffix"])) { $Suffix = $_POST["Suffix"]; } if(isset($_POST["Address"]) && !empty ($_POST["Address"])) { $Address = $_POST["Address"]; } else { echo "<br />\n"; } if(isset($_POST["CityState"]) && !empty ($_POST["CityState"])) { $CityState = $_POST["CityState"]; } else { echo " <strong> You didn't choose a City, State </strong> "; echo " <br /> "; die(); } if(isset($_POST["Zip"]) && !empty ($_POST["Zip"])) { $Zip = $_POST["Zip"]; } else { echo "<strong>You didn't enter Zip Code</strong>"; echo " <br /> "; die(); } if(isset($_POST["Email"]) && !empty ($_POST["Email"])) { $Email = trim($_POST["Email"]); //### check if e-mail address is well-formed if (!filter_var($Email, FILTER_VALIDATE_EMAIL)) { echo $Email . " <strong>is not a valid email address</strong>"; } } } //### Call Functions test1_1(); test1_2(); function test1_1(){ //### Write order to file appointment.txt global $Test_number, $Date, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; if(is_readable($file)) { echo " "; } else { echo '<strong>The file is not readable</strong>\n\n'; die(); } if(is_writable($file)) { echo " "; } else { echo '<strong>The file is not writable</strong>'; die(); } //### Open file if(!$fh) { die("couldn't open file <i>$myFile</i>"); } else { $str = "\r\n"; $str.= "Test1 - $Test_number\r\n"; $str.= "Date: $Date\r\n"; $str.= "Name:\r\n"; $str.= "\t\t $Title $FnameUc $LnameUc $Suffix\r\n"; $str.= "Address:\r\n"; $str.= "\t\t $Address\r\n"; $str.= "City, State:\r\n"; $str.= "\t\t $CityState $Zip\r\n"; $str.= "\t\t $Email \r\n"; $str.= "Comments:\r\n"; $str.= "\t\t $Comments\r\n"; $str.= "\r\n"; $str.= "\r\n"; fwrite($fh, $str); } fclose($fh); } function test1_2() { //### Email (HTML) Someone global $Test_number, $Date, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define Variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test1"; //### Beginning of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> $Title $LnameUc, <br> We have received your Test. <br> The information you submitted is below: <br> <b>$Title $FnameUc $LnameUc $Suffix</b> <br> <b>$Address</b> <br> <b>$CityState $Zip</b> <br> <b>$Email</b> <br><br> Comments: <br> <b>$Comments</b> <br><br> Please click your <b><u>Confirm Email Address</u></b> ,below, to confirm your email address. <br><br> * * * * * * * * * * <a href="http://www.mydomain.com/test2.php?test_number= $Test_number&date=$Date&title=$Title&fname=$FnameUc&lname=$LnameUc&suffix=$Suffix&address=$Address&citystate= $CityState&zip=$Zip&email=$Email&comments=$Comments">Confirm Email Address - $Test_number</a> * * * * * * * * * * <br><br> </body> </html> EOF; //end of message $headers = "Mime-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From:" .$From . "\r\n"; $headers .= "Reply To:". $From . "\r\n"; $headers .= "Return-Path:" .$From . "\r\n"; $headers.= "BCC: me@mydomain.net\r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; $headers .= "Importance: High\r\n"; //### now lets send the email if(mail($mailto, $subject, $message, $headers)) { echo "<b> <font color='green' size='+2'> Test1 sent.</font></b>"; } else { echo "<b> <font color='red' size='+2'>Test1 not sent.</b></font>"; } } ?> TEST2.PHP <?php //### Test2.php called by Test1.php //### Error Reporting error_reporting(E_ALL); //### Define varibles $Date = $_GET["date"]; $Appointment_number = $_GET["appointment_number"]; $Title = $_GET["title"]; $FnameUc = $_GET["fname"]; $LnameUc = $_GET["lname"]; $Suffix = $_GET["suffix"]; $Address = $_GET["address"]; $CityState = $_GET["citystate"]; $Zip = $_GET["zip"]; $Email = $_GET["email"]; $Comments = $_GET["comments"]; //### Call Function(s) test2_1(); test2_2(); //### HTML Email to Client function test2_1() { global $Date, $Test_number, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test2 - ". $Test_number."\r\n"; //### Beginning of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> $Title $FnameUc $LnameUc $Suffix <br> Your email address <b><$mailto></b> is confirmed. <br><br> </body> </html> EOF; //### end of message $headers = "Mime-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From: ".$From. "\r\n"; $headers .= "Reply-To: ".$From. "\r\n"; $headers .= "Return-Path: ".$From. "\r\n"; $headers .= "BCC: horacef@horacefranklinjr.net \r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; //### Now lets send the email if(mail($mailto, $subject, $message, $headers)) { echo "<b> <font color='green' size='+2'>Email address Confirmation sent to: ".$mailto."</font></b>"; echo "<br /> <br />"; } else { echo "<b> <font color='red' size='+2'>Email address Confirmation not sent.</font></b>"; echo "<br /> <br />"; } } //### HTML Email to Horace function test2_2() { global $Date, $Appointment_number, $Title, $FnameUc, $LnameUc, $Suffix, $Address, $CityState, $Zip, $Email, $Comments; //### Define variables $mailto = $Email; $From = "me@mydomain.com"; $subject = "Test2 - ". $Test_number."\n\n"; //### begin of HTML message $message = <<<EOF <html> <body BGCOLOR="tan" TEXT="black"> <br><br> You have received an Test, <b>that needs to be confirmed.</b> <br> Date Received: <b>$Date</b> <br><br> The information submitted is below: <br> <b>$Title $FnameUc $LnameUc $Suffix</b> <br> <b>$Address</b> <br> <b>$CityState $Zip</b> <br> <b>$mailto</b> <br><br> Comments: <br> <b>$Comments</b> <br><br> Please click the <b><u>Confirm Appointment</u></b> ,below, to confirm the Appointment Date and Time. <br><br> <a href="http://www.mydomain.com/Test3.php?date=$Date&test_number=$Test_number&title=$Title&fname=$FnameUc&lname=$LnameUc&suffix=$Suffix&address=$Address&citystate=$CityState&zip=$Zip&email=$Email&comments=$Comments"> Confirm Appointment - $Test_number</a> <br> </body> </html> EOF; //###end of message $headers = "Mime-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "Sensitivity: Personal\r\n"; $headers .= "From:" . $From . "\r\n"; $headers .= "Reply-To:" . $From . "\r\n"; $headers .= "Return-Path:" . $From . "\r\n"; $headers .= "BCC: me@mydomain.net\r\n"; $headers .= "X-Priority: 1 (Highest)\r\n"; $headers .= "X-MSMail-Priority: High\r\n"; //### Now lets send the email if(mail($mailto, $subject, $message, $headers)){ echo "<b> <font color='green' size='+2'> Confirm Appointment email sent to: ". $mailto."</b></font>"; echo "<br /> <br />"; } else { echo "<b> <font color='red' size='+2'> Confirm Appointment email not sent.</b></font>"; echo "<br /> <br />"; } ==> Line 114 }
  8. There is a nice tool to check markup html:3C Internationalization Checker Is your page world ready? http://validator.w3.org/i18n-checker/ :-)
  9. Thank you for the error checking suggestion. Bad code is something newbies sometimes post during the learning process. Mistakes can be the best teacher. Thanks for the encouragement.
  10. Just, what I needed 'Constructive Criticism'. I will rewrite r he code to meet html5 specifications. Thank you.
  11. 1. The browser (Firefox 34.04) stays on the html page. 2. html and php are separated files. Questions: 1. Would Registered Globals off cause this problem? 2. Would accessing html page from mobile device prevent submit button from working? <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Replace or Upgrade Service Order </title> </head> <body bgcolor="#000080"> <form action="test.php" method="POST"> <table align="center" width="668"> <tr> <td align="center"> <font size="+3" color="#ffff00"> <b>~ ~ Replace or Upgrade Service Order ~ ~</b> </font> </td> </tr> </table> <br> <table width="668" align="center"> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffffff"> <b>* </b> </font> </td> <td align="left" valign="middle" colspan="1"> <font color="#ffffff"> <b>Required Fields</b> </font> </td> </tr> </table> <table width="668" align="center"> <tr> <td align="right" valign="middle" colspan="1" width="170"> <font color="#fffff00"> <b>Age Verification: * </b> </font> </td> <td align="left" valign="middle" colspan="1"> <INPUT type="radio" name="Eighteen" Value="Yes"> <font color="#ffffff"> {Note 1 at bottom of page} </font> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Type Order: * </b> </font> </td> <td align="left" valign="middle" colspan="1"> <font color="#ffff00"> New </font> <INPUT type="radio" name="List_2" VALUE="New"> <font color="#ffff00"> Revised </font> <INPUT type="radio" name="List_2" VALUE="Revised"> <font color="#ffffff"> {Note 2 at bottom of page} </font> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Confirmation #: * </b> </font> </td> <td align="left" valign="middle" colspan="1"> <INPUT type="text" name="confirmation_2" size="10" maxlength="10"> <font color="#ffffff"> {Note 3 at bottom of page} </font> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Type Service: * </b> </font> </td> <td align="left" valign="middle" colspan="1"> <font color="#ffff00"> Replace </font> <INPUT type="radio" name="List" VALUE="Replace"> <font color="#ffff00"> Upgrade </font> <INPUT type="radio" name="List" VALUE="Upgrade"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Date Service Needed: * </b> </font> </td> <td align="left" valign="middle" colspan="1"> <input type="text" name="Dsn" size="10" maxlength="10"> <font color="#ffffff"> {Format: mm-dd-yyyy} </font> <select size="1" name="Hour"> <option value="" selected>[Time]</option> <option value="7:00AM"> 7:00AM</option> <option value="7:30AM"> 7:30AM</option> <option value="8:00AM"> 8:00AM</option> <option value="8:30AM"> 8:30AM</option> <option value="9:00AM"> 9:00AM</option> <option value="9:30AM"> 9:30AM</option> <option value="10:00AM"> 10:00AM</option> <option value="10:30AM"> 10:30AM</option> <option value="11:00AM"> 11:00AM</option> <option value="11:30AM"> 11:30AM</option> <option value="12:00PM"> 12:00PM</option> <option value="12:30PM"> 12:30PM</option> <option value="1:00PM"> 1:00PM</option> <option value="1:00PM"> 1:30PM</option> <option value="2:00PM"> 2:00PM</option> <option value="2:30PM"> 2:30PM</option> <option value="3:00PM"> 3:00PM</option> <option value="3:30PM"> 3:30PM</option> <option value="4:00PM"> 4:00PM</option> <option value="4:30PM"> 5:30PM</option> <option value="5:00PM"> 5:00PM</option> <option value="5:30PM"> 5:30PM</option> <option value="6:00PM"> 6:00PM</option> </SELECT> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Title: </b> </font> </td> <td align="left" valign="top" colspan="1"> <select name="Title" size="1" > <option value="" selected>Please choose</option> <option value="Mr."> Mr.</option> <option value="Ms."> Ms.</option> <option value="Mrs."> Mrs.</option> </SELECT> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>First Name: * </b> </font> </td> <td align="left" valign="top" colspan="1"> <input type="text" name="Fname" size="30" maxlength="30"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Last Name: * </b> </font> </td> <td align="left" valign="top" colspan="1"> <input type="text" name="Lname" size="30" maxlength="30"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Suffix: </b> </font> </td> <td align="left" ="top" colspan="1"> <select name="Suffix" size="1"> <option value="" selected>Please choose</option> <option value="Sr."> Sr.</option> <option value="Jr."> Jr.</option> <option value="III"> III</option> <option value="IV"> IV</option> <option value="V"> V</option> </select> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Address: </b> </font> </td> <td align="left" valign="top" colspan="1"> <input type="text" name="Address" size="40" maxlength="40"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>City/State: * </b> </font> </td> <td align="left" valign="top" colspan="1"> <select name="CityState" size="1"> <option value="" selected>Please choose</option> <option value="Fairfield, CA"> Fairfield, CA</option> <option value="Suisun City, CA"> Suisun City, CA</option> <option value="Vallejo, CA"> Vallejo, CA</option> </select> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Zip Code: </b> </font> </td> <td align="left" valign="top" colspan="1"> <input type="text" name="Zip" size="5" maxlength="5"> <font color="#ffffff"> {Format: 99999} </font> </td> </tr> </table> <table width="667" align="center"> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Email Address: * </b> </font> </td> <td align="left" valign="top" colspan="1" width="492"> <input type="text" name="Email" size="54" maxlength="54"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="170"> <font color="#ffff00"> <b>Telephone: * </b> </font> </td> <td align="left" valign="top" colspan="1" width="492"> <input type="text name="Phone" size="12" maxlength="12"> <font color="#ffffff"> {Format: 999-999-9999} </font> </td> </tr> </table> <br> <table width="668" align="center"> <tr> <td align="center"> <font size="+2" color="#ffffff"> <b>Computer Information</b> </font> <br><br> </td> </tr> </table> <table width="668" align="center"> <tr> <td align="right" valign="middle" colspan="1" width="159"> <font color="#ffff00"> <b>Type: </b> </font> </td> <td align="left" valign="top" colspan="1" width="150"> <font color="#ffff00"> Desktop </font> <INPUT TYPE="radio" NAME="TypeComputer" VALUE="Desktop"> <font color="#ffff00"> Laptop </font> <INPUT TYPE="radio" NAME="TypeComputer" VALUE="Laptop"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="165"> <font color="#ffff00"> <b>Brand: </b> </font> </td> <td align="left" valign="top" colspan="1" width="492"> <input type="text" name="ComputerBrand" size="40" maxlength="40"> </td> </tr> <tr> <td align="right" valign="top" colspan="1" width="165"> <font color="#ffff00"> <b>Model: </b> </font> </td> <td align="left" valign="top" colspan="1" width="492"> <input type="text" name="ComputerModel" size="40" maxlength="40"> </td> </tr> </table> <br> <table width="668" align="center"> <tr> <td align="center" valign="top" colspan="1" width="667" > <font color="#ffffff" size="+2"> <b>Items to be Replaced or Upgraded</b> </font> <br> <font color="#ffff00"> <b>{Notes 4 and 5 at bottom of page}</b> </font> <br> </td> </tr> </table> <br> <table width="668" align="center"> <tr> <td align="left" colspan="1" width="167"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="Dvd"> <font color="#ffff00"> <b>DVD</b> </font> </td> <td align="left" colspan="1" width="167"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="Dvd_rw"> <font color="#ffff00"> <b>DVD+RW</b> </font> </td> <td align="left" colspan="1" width="290"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="HardDrive"> <font color="#ffff00"> <b>Hard drive</b> </font> </td> </tr> <tr> <td align="left" colspan="1" width="290"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="Memory"> <font color="#ffff00"> <b>Memory</b> </font> </td> <td align="left" colspan="1" width="167"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="ModemCard"> <font color="#ffff00"> <b>Modem Card</b> </font> </td> <td align="left" colspan="1" width="191"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="MultimediaCard"> <font color="#ffff00"> <b>Multimedia Card</b> </font> </td> </tr> <tr> <td align="left" colspan="1" width="290"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="NetworkCard"> <font color="#ffff00"> <b>Network Card</b> </font> </td> <td align="left" colspan="1" width="167"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="Software"> <font color="#ffff00"> <b>Software</b> </font> </td> <td align="left" colspan="1" width="191"> <input type="checkbox" name= "ReplaceUpgrade[]" size="1" maxlength="1" value="SoundCard"> <font color="#ffff00"> <b>Sound Card</b> </font> </td> </tr> <tr> <td align="left" colspan="1" width="290"> </td> <td align="left" colspan="1" width="290"> <input type="checkbox" name="ReplaceUpgrade[]" size="1" maxlength="1" value="Speakers"> <font color="#ffff00"> <b>Speakers</b> </font> </td> <td align="left" colspan="1" width="191"> </td> </tr> </table> <br><br> <table width="668" align="center"> <tr> <td align="center" valign="middle" colspan"1" width="165"> <font size="+2" color="#ffffff"> <b>Comments</b> </font> <br> <textarea name="Comments" rows="8" cols="60" wrap="physical"></textarea> </td> </tr> </table> <br> <table width="668" align="center"> <tr> <td align="center" width="668"> <input type="submit" value="Submit Form"> </td> </tr> </table> <br><br> <table align="left" width="850" border="10"> <tr> <td align="left" width="850"> <font color="#ffffff" size="+1"> <b>Notes:</b> </font> <font color="#ffff00" size="+1"> 1. <i><u><b>You</u> must be 18 or older to submit an order.</i></b> </font> </td > </tr> <tr> <td align="left" width="850"> <font color="#ffff00" size="+1"> <i><b> By selecting Age 'Verification' above you are affirming you are at least 18 years of age.</i></b> </font> </td> </tr> <tr> <td align="left" width="850"> <font color="#ffffff" size="+1"> <b> 2. Confirmation number for <i><u>New Order will 'Appear'</i></u> when you <u><i>'Submit'</i></u> your order.</b> </font> </td> </tr> <tr> <td align="left" width="850"> <font color="#ffff00" size="+1"> <b>3. Confirmation number is <u><i>'REQUIRED' for 'Revised Order'</i></u></b> </font> </td> </tr> <tr> <td align="left" width="850"> <font color="#ffffff" size="+1"> <b>4. <i>Hardware</i> -- Diagnose, Replace or Upgrade</b> </font> </td> </tr> <tr> <td align="left" width="850"> <font color="#ffff00" size="+1"> <b>5. <i>Software</i> -- Install/Setup or Upgrade</b> </font> </td> </tr> </table> </form> </body> </html>
  12. Help! HTML5 Submit button not calling PHD file My HTML: <html> <head> </head> <body> <form action="my.php" method="POST" name="process_form"> <Input type="submit" name="submit" value="Submit" formmethod="post" formaction="my.php"> </form> </body> </html> PHP if(isset ($_POST["submit"])){ Do something; Do something; } else { Do something; Do something; } I click the button and nothing happens. What am I missing?
  13. I am trying to redirect the user to a different Web site after they enter a password. I have two problems, I think. a. My phone file is not retrieving the 'input' from my html5 form. b. My phone header is not working: header (' location: http://filefippo.com'); What is wrong with my coding? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="keywords" content="html"> <meta http-equiv="refresh" content "1800"> <link rel="stylesheet" href="menu_blue.css" type="text/css" media="screen" /> <title>Members 2</title> <script src="http://1.2.3.4/bmi-int-js/bmi.jsversion=1350564613" language="javascript"> </script> <!--[if IE 6]> <style> body {behavior: url("csshover3.htc");} #menu li .drop {background:url("img/drop.gif") no-repeat right 8px; </style> <![endif]--> </head> <body bgcolor="#000080"> <ul id="menu"> <li> <a href="index.html">Home</a> <!-- Home page --> </li> <!-- End Home page --> <li> <a href="contactform.html">Contact</a> <!-- Contact page --> </li> <!-- End Contact page --> <li> <a href="feedbackform.html">FeedBack</a> <!-- Feedback Page --> </li> <!-- End Feedback page --> <li> <a href="construc.html">Free Estimate</a> <!-- Free Estimate Page --> </li> <!-- End Free Estimate page --> <li> <a href="construc.html">Humor</a> <!-- Humor Page --> </li> <!-- End Free Humor page --> <li> <a href="#" class="drop">Other Links</a> <!-- Other Links Page --> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li> <a href="construc.html"> Members</a></li> <li> <a href="military.html"> Military</a></li> </ul> </div> </div> </li><!-- End Other Links page --> <li> <a href="repair_upgradeform.html">Repair/Upgrade</a> <!-- Repair/Upgrade Page --> </li><!-- End Repair/Upgrade page --> <li class="menu_right"> <a href="#" class="drop">Training</a> <!-- Training Page --> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li> <a href="tng_appsform.html"> Applications</a></li> <li> <a href="tng_hardwareform.html"> Hardware</a></li> <li> <a href="tng_osform.html"> Operating Systems</a></li> </ul> </div> </div> </li><!-- End Training page --> </ul> <br> <form name="myform" method="post" action="members2.php"> <table width="100%" align="center" bgcolor="#000080"> <tr> <th align="center" > <font size="+2" color=#ffff00"> ~ ~ ~ Member ~ ~ ~ </font> <br> </th> </tr> </table> <br> <table width="699" bgcolor="#000080" align="center"> <tr align="center"> <td align="center"> <input type="password" name="password" maxlength="15" size="15"> </td> </tr> </table> <table width="699" bgcolor="#000080" align="center"> <tr align="center"> <td align="center"> <font color="#ffffffff" size="+1"> (Please enter the password on your receipt) </font> </td> </tr> </table> <br> <table width="669" bgcolor="#000080" align="center"> <tr> <td align=center> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </td> </tr> </table> </form> <script language="JavaScript" type="text/javascript"> //You should create the validator only after the definition of the HTML form var frmvalidator = new Validator("myform"); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("Password","req","Please enter the Password."); frmvalidator.addValidation("Password","maxlen=15","Max length for the Password is 15"); frmvalidator.addValidation("Password","alnum_s","Password - Alphabetic and Numeric chars"); </script> </body> </html> <script language="javascript"><!--//bmi_orig_img 0 // --> </script> PHP CODE <?php ob_start(); // Process membersform2.html error_reporting(-1) ; // Get Data From Form if ($_SERVER["REQUEST_METHOD"] == "POST") { if(isset($_POST["password"])) { $password = $_POST["passwords"]; trim($password); echo "$Password"; } else { if(empty($_POST["password"])) { echo "Password is required"; } } } // Validate Pwd if($password == "Z0y1X2w3V"){ header(' Location: http://filehippo.com/ '); exit; }else { members(); } // FUNCTION function members(){ // Print to browser global $password; // echo " <html>\n"; echo " <head>\n"; echo " <title>Redirect</title>\n"; echo " </head>\n"; echo " <body BGCOLOR=\"#000080\" TEXT=\"#ffff00\">\n"; echo " <table width=\"600\" Align=\"center\">\n"; echo " <tr>\n"; echo " <td width=\"600\" Align=\"left\">\n"; echo " You will be redirected to the members page in a moment.\n"; echo " <br />\n"; echo " $password \n"; echo " <br /><br />\n"; echo " </td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </body>\n"; echo " </html>"; } ob_flush(); ?>
  14. Still can't find confirmation number, line 41 -- No errors <?php //### Process edit_textform error_reporting(-1); //### Define Variable //$filename = "repair_upgrade.txt"; //### Get Data From Form $filename = isset($_POST['file_name']) ? $_POST['file_name'] : FALSE ; //### Validate filename if(empty($filename)) { echo "You did not enter a file name i.e. myfile.txt.". PHP_EOL; exit; } else { echo ""; } $confirmation_number = isset($_POST['confirmation_number']) ? $_POST['confirmation_number'] : FALSE ; //### Validate confirmation number if(empty($confirmation_number)) { echo 'No confirmation number.'. PHP_EOL; exit; } else { //### Remove anything that is a not a number $searchfor = preg_replace('#[\D]#', '', $confirmation_number); } ///### check if file exist & is readable if (!file_exists($filename)) { echo 'The file does not exist'. PHP_EOL; exit; } if (!is_readable($filename)) { echo 'The file is not readable'. PHP_EOL; exit; } //Define Variable(s) $found = false; ///### Put Text File into Array $array = file($filename); ///### Rewind array to first element reset($array); **** //### Search for string if(in_array($searchfor, $array)){ $found = true; echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; while($array = fgets($line, 1000)) { foreach($line as $text) { echo $text; } } echo "</textarea>"; echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; print "<br/><br/>"; //### Put text file in Array $array = file($filename); foreach($array as $line){ $line = rtrim($line); print $line . "<br/>"; } } else { echo "Confirmation number not found."; } ?>
  15. I am trying ti edit a record in a text file. The problem is I cannot find the $confirmation_number: This line => if(strpos("Confirmarion Number:".$confirmation_number, $array) !== FALSE) { <?php //### Process edit_textform error_reporting(-1); //### Define Variable //### Get Data From Form $filename = isset($_POST['file_name']) ? $_POST['file_name'] : FALSE ; //### Validate filename if(empty($filename)) { echo "You did not enter a file name i.e. myfile.txt.". PHP_EOL; exit; } else { echo ""; } $confirmation_number = isset($_POST['confirmation_number']) ? $_POST['confirmation_number'] : FALSE ; //### Validate confirmation number if(empty($confirmation_number)) { echo 'No confirmation number.'. PHP_EOL; exit; } else { //### Remove anything that is a not a number $searchfor = preg_replace('#[\D]#', '', $confirmation_number); } ///### check if file exist & is readable if (!file_exists($filename)) { echo 'The file does not exist'. PHP_EOL; exit; } if (!is_readable($filename)) { echo 'The file is not readable'. PHP_EOL; exit; } ///### Put Text File into Array $array = file($filename); $found = false; //### Cant fint $confirmation Number *** This Line => if(strpos("Confirmarion Number:".$confirmation_number, $array) !== FALSE) { $found = true; echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; while($line = fgets($array, 1000)) { foreach($line as $text) { echo $text; } //echo $line; //continue; } echo "</textarea>"; echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; } else { echo "Confirmation number not found."; } ?>
  16. Thanks for responding, I don't think the end result is worth the effort.
  17. I know you can edit a text file in a <textarea> with the following code I got from: http://www.dynamicdrive.com/forums/showthread.php?4539-how-do-i-modify-existing-txt-files-with-php <? if($_POST['Submit']){ $open = fopen("textfile.txt","w+"); $text = $_POST['update']; fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File:<br />"; $file = file("textfile.txt"); foreach($file as $text) { echo $text."<br />"; } } else{ $file = file("textfile.txt"); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; foreach($file as $text) { echo $text; } echo "</textarea>"; echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>"; } ?> I'm thinking is it possible to edit a specific record in a text file in a <textarea>. <? //### Process edit_textform error_reporting(-1); //### Define Variable $filename = "repair_upgrade.txt"; $path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/"; $searchfor = preg_replace('#[\D]#', '', $confirmation_number); //### Get Data From Form $confirmation_number = isset($_POST['confirmation_number']) ? $_POST['confirmation_number'] : FALSE ; //### Validate confirmation number if(empty($confirmation_number)) { echo 'No confirmation number.'. PHP_EOL; exit; } else { //### Remove anything that is a not a number $confirmation_number = preg_replace('#[\D]#', '', $confirmation_number); } //### Check if file is writable if(!is_writable($filename)) { echo 'The file is not writable.'. PHP_EOL; exit; } //### Check if file is readable if (!is_readable($filename)) { echo 'The file is not readable'. PHP_EOL; exit; } elseif($searchfor) != FALSE) { //### Search file for Confirmation_number. $file = file($filename); //### Set pointer to current record fseek($file, SEEK_CUR); echo "<form action=\"".$PHP_SELF."\" method=\"post\">"; echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">"; While(!preg_match('/\bEND\b/i',$file)) { foreach($file as $text) { echo $text; } } echo " </textarea><br />\n"; echo " <input name=\"Submit\" type=\"submit\" value=\"Update\" />\n </form>\n"; } else { if($_POST['Submit']){ $open = fopen($filename,"a+"); $text = $_POST['update']; fwrite($open, $text); fclose($open); echo "File updated.<br />"; echo "File: $filename <br />"; } $file = file($filename); foreach($file as $text) { echo $text."<br />"; } fclose($fh); } ?>
  18. PaulRyan: I replaced line 46: $searchfor = $confirmation_number; $searchfor = preg_replace('#[\D]#', '', $confirmation_number); I'm still receiving Line 62: I can't find the number you are searching for - 2026540492 Â echo "I can't find the number you are searching for - $searchfor\n\n"; I have made several changes to the code: <?php // Process valid_repair_upgradeform error_reporting(-1); //Define Variable(s) $date = date("D d M Y - H:i:s "); $my_file = "s_vcs.txt"; $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/"; $my_name = "Newbieca"; $my_mail = "coon-a@gmx.com"; $my_replyto = "coon-a@gmx.com"; $my_subject = "Order Validated"; $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n"; if (is_writable($my_file)) { echo " "; } else { echo 'The file is not writable\n\n'; } if (is_readable($my_file)) { echo " "; } else { echo 'The file is not readable'; } //Get Data From Form $confirmation_number = $_POST['confirmation_number']; $Email = $_POST['Email']; $List = array(); // validate expected data exists if(!isset($_POST['confirmation_number'])) { echo "No Confirmation_number.\n"; die(); } if(!isset($_POST['Email'])) { echo "No Email address.\n"; die(); } //validate email address if (check_email_address($Email)) { echo " "; } else { echo $Email . " is not a valid email address.\n"; die(); } // Search file for Confirmation_number. If found call function $MyFile = "s_vcs.txt"; $searchfor = preg_replace('#[\D]#', '', $confirmation_number); $fh = fopen($MyFile, "r"); if (is_readable($MyFile)) { echo " "; } else { echo 'The file is not readable'; } $olddata = fread($fh, filesize($MyFile)); if(strpos($olddata, $searchfor)) { echo "fount it"; // Call Functions mail_attachment($my_file, $my_path, "horacfe@netscape.com", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); email(); } else { } fclose($fh); //FUNCTION(S) 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 mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { // Email phpnewbieca with attachment global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $MyFile, $searchfor, $fh, $olddata; // $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file,"r"); $content = fread($handle,$file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } } function email() { // Email Customer HTML global $date, $my_file, $my_path, $my_name, $my_mail, $my_replyto, $my_subject, $my_message, $confirmation_number, $Email, $List, $MyFile, $searchfor, $fh, $olddata; //Stuff Array if(isset($_POST['confirmation_number'])) { $List[0]="$confirmation_number<br><br>"; } else { $List[0]=" "; } if(isset($_POST['Email'])) { $List[1]="$Email<br>"; } else { $List[1]=" "; } $to = "$Email"; $subject = "RE: Validation of Repair/Upgrade Order\n\n"; //begin of HTML message $message = <<<EOF <html> <body BGCOLOR='tan' TEXT='black'><br> <br> <Font size="1+"><b>Thank you for validating your order $date.</font></b><br> CONFIRMATION NUMBER: $List[0] <Font size="1+">Please visit us again <a href="http://www.horacefranklinjr.com/"> Horace's Home Computer Repair<Font></a> </body> </html> EOF; //end of message $headers = "Mime-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" ."\r\n"; $headers .= "Sensitivity: Personal" . "\r\n"; $headers .= "From: $From" . "\r\n"; $headers .= "Reply To: $From" . "\r\n"; $headers .= "Return-Path: $From" . "\r\n"; $headers .= "X-Priority: 1 (Highest)" . "\r\n"; $headers .= "X-MSMail-Priority: High" . "\r\n"; $headers .= "Importance: High" . "\r\n"; // now lets send the email. mail($to, $subject, $message, $headers); echo " "; } ?>
  19. PaulRayan: I fixed line 33: $fh = fopen($MyfFile, "r"); Thank you! mac_gyver: (1) I fixed line 33: $fh = fopen($MyfFile, "r"); (2) Line 24: $confirmation_number = $_POST['confirmation_number']; Line 31: $MyFile = "s_vcs.txt"; Line 32: $searchfor = trim($confirmation_number); Line 33: $fh = fopen($MyfFile, "r"); Line 34: $olddata = fread($fh, filesize($MyFile)); Line 35: if(strpos($olddata, trim($searchfor))) { Line 36: echo "fount it"; Line 37: // Call Functions Line 38: mail_attachment($my_file, $my_path, "horacfe@netscape.com", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); Line 39: }40: Line 40: else { Line 41: echo "I can't find the number you are searching for - $searchfor\n\n"; Line 42: } Note: Line 35 (above) produced this error: PHP Parse error: syntax error, unexpected T_STRING in on line 35 So, I removed the tirm() from line 35 after I posted the CODE: if(strpos($olddata, $searchfor)) { Now, I am getting line 41: I can't find the number you are searching for - 2026540492 Â <?php // Process valid_repair_upgradeform error_reporting(-1); //Define Variable(s) $date = date("D d M Y - H:i:s "); $my_file = "s_vcs.txt"; $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/"; $my_name = "Newbieca"; $my_mail = "coon-a@gmx.com"; $my_replyto = "coon-a@gmx.com"; $my_subject = "Order Validated"; $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n"; if (is_writable($my_file)) { echo " "; } else { echo 'The file is not writable\n\n'; } if (is_readable($my_file)) { echo " "; } else { echo 'The file is not readable'; } //Get Data From Form $confirmation_number = $_POST['confirmation_number']; // validate expected data exists if(!isset($_POST['confirmation_number'])) { echo "No Confirmation_number.\n"; die(); } // Search file for Confirmation_number. If found call function $MyFile = "s_vcs.txt"; $searchfor = trim($confirmation_number); $fh = fopen($MyfFile, "r"); $olddata = fread($fh, filesize($MyFile)); if(strpos($olddata, trim($searchfor))) { echo "fount it"; // Call Functions mail_attachment($my_file, $my_path, "horacfe@netscape.com", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); } else { echo "I can't find the number you are searching for - $searchfor\n\n"; } fclose($fh); //FUNCTION(S) function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file,"r"); $content = fread($handle,$file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } } ?>
  20. What happened to post #4? Quote #4 Newbie Hi. Maybe you can try utting the xml tag in the first line of your file.
  21. The string $searchfor has this in it: I can't find the number you are searching for - searchfor: 2026540492 Â Line 42: echo "I can't find the number you are searching for - searchfor: $searchfor" I do not understand why there is a character after the number: Line 32: $searchfor = rtrim($confirmation_number); How can I get rid of the character after the number, 2026540492 Â, and remove all spaces before and after the number? <?php // Process valid_repair_upgradeform error_reporting(-1); //Define Variable(s) $date = date("D d M Y - H:i:s "); $my_file = "s_vcs.txt"; $my_path = $_SERVER['DOCUMENT_ROOT']."/home/users/web/b686/dom.horacela/public_html/"; $my_name = "Newbieca"; $my_mail = "coon-a@gmx.com"; $my_replyto = "coon-a@gmx.com"; $my_subject = "Order Validated"; $my_message = "This order was validated Confirmation Number: $confirmation_number on Date: $date.\r\n\r\n"; if (is_writable($my_file)) { echo " "; } else { echo 'The file is not writable\n\n'; } if (is_readable($my_file)) { echo " "; } else { echo 'The file is not readable'; } //Get Data From Form $confirmation_number = $_POST['confirmation_number']; // validate expected data exists if(!isset($_POST['confirmation_number'])) { echo "No Confirmation_number.\n"; die(); } // Search file for Confirmation_number. If found call function $MyFile = "s_vcs.txt"; $searchfor = rtrim($confirmation_number); $fh = fopen(MyfFile, "r"); $olddata = fread($fh, filesize($MyFile)); if(strpos($olddata, $searchfor)) { echo "fount it"; // Call Functions mail_attachment($my_file, $my_path, "horacfe@netscape.com", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); } else { echo "I can't find the number you are searching for - confirmation_number: $confirmation_number"; echo "<br>"; echo "I can't find the number you are searching for - searchfor: $searchfor\n\n"; } fclose($fh); //FUNCTION(S) function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) { $file = $path.$filename; $file_size = filesize($file); $handle = fopen($file,"r"); $content = fread($handle,$file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($mailto, $subject, "", $header)) { echo "mail send ... OK"; // or use booleans here } else { echo "mail send ... ERROR!"; } } ?>
×
×
  • 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.