473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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, 541 views)
File Type: txt handle3.txt (1.2 KB, 546 views)
File Type: txt test3.txt (1.4 KB, 344 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 2773
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: <?php require_once('Connections/carresa.php'); ?>...
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 5 that I installed on my server. After...
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 following "END". Expected tokens may include: "JOIN...
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 View' property set to 'Continuous Forms' and am...
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 substr(tablespace_name,1,30) as "Tablespace Name", case...
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 this is the section of code. if (isset($row4)) {...
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 terminated by a *space* followed by a newline ...
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: application/xmsdownload"); header("Content-Disposition:...
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 php worked on my 4.x php server but I get...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.