473,659 Members | 3,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unexpected $end and the If...Else statement

3 New Member
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, 546 views)
File Type: txt handle3.txt (1.2 KB, 550 views)
File Type: txt test3.txt (1.4 KB, 349 views)
Nov 13 '09 #1
4 2788
Markus
6,050 Recognized Expert Expert
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
maveri4201
3 New Member
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 Recognized Expert Expert
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
maveri4201
3 New Member
Perfect! Thank you! (............ad ding 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
34700
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'); ?> <?php $DateTime = date("Y/n/j");
6
19023
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 submitting user information into my creation script, I get the following error from the page that is suppose to insert the user data into the database, create a code, then send an email out for verification. Parse error: parse error, unexpected $end in...
1
30252
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 <joined_table> Explanation: A syntax error in the SQL statement was detected at the specified token following the text "<text>". The "<text>" field indicates the 20 characters of the SQL statement that preceded the token
6
3178
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 displaying records that match an SQL statement entered in the 'Record Source' property of the form. The form behaves correctly and displays the records as expected. The
2
19997
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 (tablespace_type) when 0 then 'DMS' else 'SMS' end as "Type",
8
2810
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)) { if (isset($row5)) { //answer given? if ($row4==$row5) {
7
2779
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 What surprised me was that the csv reader included the trailing space in the final field value returned, even though it is outside of the quotes.
11
2924
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: attachment; header("Pragma: no-cache"); header("Expires; 0"); print "$header\n$data";
6
1785
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 unexpected end with any other. Needless to say I only upgraded to 5.2 because Yellowtip web server 2.0's php did not come with the GD librarys which I needed to upload pics using mini file host. If you can fix ethier problem I would be so greatful
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.