472,351 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

Unexpected $end and the If...Else statement

I have written a php script (test3.php), which I attached as a text file. Its includes are also attached as text files. I'm trying to run the script here: http://www.wondergy.com/phptestbed/test3.php

The problem I'm having is the frustrating Unexpected $end. Yes, I know that it usually means something isn't being closed correctly. The problem is, I can't figure out what. To make the problem stranger, I can get it to parse when I break it up into three files and include the two files in a large If...Else statement. The first time the script runs, it goes to the Else part of the statement and includes form3.php. Perfect, the form displays and the world is happy. No unexpected $end error. BUT - when I take that very same code (from form3.php) and include it inside the else brackets {}, I get the unexpected $end error. How can this be? How can I fix this?
Attached Files
File Type: txt form3.txt (776 Bytes, 527 views)
File Type: txt handle3.txt (1.2 KB, 521 views)
File Type: txt test3.txt (1.4 KB, 327 views)
Nov 13 '09 #1

✓ answered by Markus

On line 33 of handle3.php, make sure EMAIL_RESPONSE has no whitespace before it, that is, it should be the very first thing on the line. Consider the following:

Expand|Select|Wrap|Line Numbers
  1. // good
  2.     echo <<<HTML
  3.     <input>...</input>
  4. HTML;
  5. // bad
  6.     echo <<<HTML
  7.     <input>...</input>
  8.     HTML;
  9.  
Mark.

4 2655
Markus
6,050 Expert 4TB
The error text is? Short of running the code ourselves (extra effort on our part) we do not know what part of the code we should be looking at. Also, instead of providing the files as attachments, if the files do not have 1000+ lines, just post them here (wrapped with [code] tags) for us to see.

Mark.
Nov 13 '09 #2
The exact error message is as follows:
Parse error: syntax error, unexpected $end in ../handle3.php on line 49

test3.php:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Email Form</title>
  6. </head>
  7. <body>
  8.  
  9. <?php
  10. /* This is a test of a form generating an email */
  11. $myaddy = "charles@wondergy.com";
  12. $file = $_SERVER['PHP_SELF'];
  13. //First, an if statement to see if the form has been submitted
  14. if (isset($_POST['submitted']))
  15. {
  16.     //check for errors
  17.     //initializing the errors array
  18.     include("handle3.php");
  19. }
  20. else
  21. {
  22.     //Show the form
  23.     include("form3.php");
  24.     /* Sends to itself again; 
  25.     Uses "submitted" as a check value */
  26.     /*echo <<<END_OF_FORM
  27.     <form action="$file" method="POST"> 
  28.     <input type="hidden" name="submitted" value="TRUE" /> 
  29.     <table>
  30.         <tr>
  31.             <td>Name:</td>
  32.             <td><input type="text" size="55"  name="name" /></td>
  33.         </tr>
  34.         <tr>
  35.             <td>Email:</td>
  36.             <td><input type="text" size="55"  name="email" /></td>        
  37.         </tr>
  38.         <tr>
  39.             <td>Subject:</td>
  40.             <td><input type="text" size="55"  name="subject" /></td>
  41.         </tr>
  42.     </table>
  43.  
  44.     <textarea name="body" rows="4" cols="62"></textarea><br />
  45.     <input type="submit" name="Submit Email" value="Submit Email" /><input type="reset" name="Reset" value="Reset This, Please." />
  46.  
  47.     </form>
  48.     END_OF_FORM;*/
  49. }
  50.  
  51.  
  52. ?>
  53. </body>
  54. </html>
  55.  
form3.php:
Expand|Select|Wrap|Line Numbers
  1. <?php    
  2.  
  3. /* Sends to itself again; 
  4. Uses "submitted" as a check value */
  5. echo <<<END_OF_FORM
  6. <form action="$file" method="POST"> 
  7. <input type="hidden" name="submitted" value="TRUE" /> 
  8. <table>
  9.     <tr>
  10.         <td>Name:</td>
  11.         <td><input type="text" size="55"  name="name" /></td>
  12.     </tr>
  13.     <tr>
  14.         <td>Email:</td>
  15.         <td><input type="text" size="55"  name="email" /></td>        
  16.     </tr>
  17.     <tr>
  18.         <td>Subject:</td>
  19.         <td><input type="text" size="55"  name="subject" /></td>
  20.     </tr>
  21. </table>
  22.  
  23. <textarea name="body" rows="4" cols="62"></textarea><br />
  24. <input type="submit" name="Submit Email" value="Submit Email" /><input type="reset" name="Reset" value="Reset This, Please." />
  25.  
  26. </form>
  27. END_OF_FORM;
  28. ?>
  29.  
handle3.php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $errors = array();
  3. //checking for each entry
  4. if (empty($_POST['name'])) 
  5. {
  6.     $errors[] = "No Name Entered";
  7. }
  8. if (empty($_POST['email'])) 
  9. {
  10.     $errors[] = "No Email Entered";
  11. }
  12. if (empty($_POST['subject'])) 
  13. {
  14.     $errors[] = "No Subject Entered";
  15. }
  16. $body = stripslashes($_POST['body']); //No other error checking for the body
  17. $message = $body;
  18. //Now checking for errors
  19. if (empty($errors))
  20. {
  21.     //Send email; Post response
  22.     $name = $_POST['name'];
  23.  
  24.     $body = "From: " . $_POST['name'] . "\nEmail: " . $_POST['email'] . "\nSubject: " . $_POST['subject'] . "\nMessage: " . $body;
  25.  
  26.     mail($myaddy, "Form Email - " . $_POST['subject'], $body, "From: " . $_POST['email']); //sends the mail
  27.  
  28.     echo <<<EMAIL_RESPONSE
  29.     <h1>Email Sent</h1>
  30.     <p>$name, your email has been sent.</p>
  31.     <p>Your message was: $message</p>
  32.     <p><a href="$file">Send another email</a></p>
  33.     EMAIL_RESPONSE;
  34. }
  35. else
  36. {
  37.     //Post error page w/ link to try again
  38.     echo "<h1>Error!</h1>\n<p>You did not complete the form. Please address the following problems and try again.</p>\n";
  39.  
  40.     echo "<ul>\n";
  41.     foreach ($errors as $key => $val)
  42.     {
  43.         //Print out a line of errors
  44.         echo "<li>$val</li>\n";
  45.     }
  46.     echo "</ul>\n<p><a href=\"$file\">Try Again</a></p>";
  47. }
  48.  
  49. ?>
  50.  
Nov 13 '09 #3
Markus
6,050 Expert 4TB
On line 33 of handle3.php, make sure EMAIL_RESPONSE has no whitespace before it, that is, it should be the very first thing on the line. Consider the following:

Expand|Select|Wrap|Line Numbers
  1. // good
  2.     echo <<<HTML
  3.     <input>...</input>
  4. HTML;
  5. // bad
  6.     echo <<<HTML
  7.     <input>...</input>
  8.     HTML;
  9.  
Mark.
Nov 13 '09 #4
Perfect! Thank you! (............adding extra characters to have more than 20....)
Nov 13 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: James Campbell | last post by:
ok, I am totally new to php and come from an asp background. I basically want to do an If > then > else > end if statement: my page is: ...
6
by: Ehartwig | last post by:
I recently created a script for user verification, solved my emailing issues, and then re-created the script in order to work well with the new PHP...
1
by: Najm Hashmi | last post by:
Hi all , I am trying to create a store procedure and I get the following error: SQL0104N An unexpected token "END-OF-STATEMENT" was found...
6
by: Cro | last post by:
Dear Access Developers, The 'Allow Additions' property of my form is causing unexpected results. I am developing a form that has its 'Default...
2
by: P | last post by:
Hi all, I'm trying to run the following code taken from http://blogs.ittoolbox.com/database/technology/archives/006045.asp# select...
8
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 ...
7
by: Andrew McLean | last post by:
I have a bunch of csv files that have the following characteristics: - field delimiter is a comma - all fields quoted with double quotes - lines...
11
by: JRough | last post by:
I'm trying to use output buffering to cheat so i can print to excel which is called later than this header(). header("Content-type:...
6
by: LordZyse | last post by:
Just so everyone can know, I would LOVE to stay with yellowtip webserver, if you know how to install the GD files to it PLEASE let me know. This...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.