Jump to content

[SOLVED] Parse error: parse error in C:\wamp\www\*\test.php on line 55


errcricket

Recommended Posts

new to php/mysql and i am trying to execute the code below, but i am getting the following error:

Parse error: parse error in C:\wamp\www\project1\test.php on line 55

 

<?php

if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
if (!isset($_POST['Email']) || $_POST['Email'] =="")
	$message = '<P>There is a problem with your email address</P>';	 

else
{
	mysql_connect("localhost", "X", "Y") or die("Failure to communicate with database");
	mysql_select_db("X");

	$as_email = mysql_real_escape_string($_POST['Email']);
	$tr_email = trim($as_email);
	$query = "INSERT INTO X(ID, Email) VALUES(NULL, '$tr_email')"; 

	$result = mysql_query($query);

	if(mysql_affected_rows() == 1)
	{
		$message = '<P>Your information has been recorded.</P>';
		$noform_var = 1;
	} 

	else
	{
		error_log(mysql_error());
		$message = '<P>ERROR</P>';
	}			   
}		

if (!isset($noform_var))
{		
	$thisfile="test.php";
	$message .<<< EOMSG

	<form method="post" action="$thisfile">
	<input type="text" name="Email" size=10>
	<input type="submit" name="submit" value="Submit">
	</form>	

	EOMSG;	
}
}	
?>

<html>
<head>
Email:<BR> 
<?php echo $message; ?>
</head>
<body>

</body>
</html> 

 

what am i doing incorrectly and thank you for any assistance.

 

p.s i dont know if this is any assistance, but i get the following from my editor:

[Error] test.php (45): PHP: Non terminated string.

[Error] test.php (40): PHP: Syntax error.

[Warning] test.php (37): PHP: ";" expected.

[Warning] test.php (37): PHP: ";" expected.

[Warning] test.php (38): PHP: ";" expected.

[Warning] test.php (38): PHP: ";" expected.

[Warning] test.php (38): PHP: ";" expected.

[Warning] test.php (39): PHP: ";" expected.

[Warning] test.php (39): PHP: ";" expected.

[Warning] test.php (39): PHP: ";" expected.

 

remove all the space in front of

EOMSG;

 

and it should work

 

thank you for the quick response dgoosens. unfortunately, i am still getting the error. did i misinterpret your instructions? do you have any other suggestions?

 

.
.
if (!isset($noform_var))
{		
	$thisfile="test.php";
	$message .<<< EOMSG

	<form method="post" action="$thisfile">
	<input type="text" name="Email" size=10>
	<input type="submit" name="submit" value="Submit">
	</form>
EOMSG;	
}
}	

.
.

have a try like this:

<?php

if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
   if (!isset($_POST['Email']) || $_POST['Email'] =="")
      $message = '<P>There is a problem with your email address</P>';    
   
   else
   {
      mysql_connect("localhost", "X", "Y") or die("Failure to communicate with database");
      mysql_select_db("X");
      
      $as_email = mysql_real_escape_string($_POST['Email']);
      $tr_email = trim($as_email);
      $query = "INSERT INTO X(ID, Email) VALUES(NULL, '$tr_email')"; 
      
      $result = mysql_query($query);
      
      if(mysql_affected_rows() == 1)
      {
         $message = '<P>Your information has been recorded.</P>';
         $noform_var = 1;
      } 
      
      else
      {
         error_log(mysql_error());
         $message = '<P>ERROR</P>';
      }            
   }      

   if (!isset($noform_var))
   {      
      $thisfile="test.php";
      $message ."
      <form method=\"post\" action=\" " . $thisfile . "\">
      <input type=\"text\" name=\"Email\" size=10>
      <input type=\"submit\" name=\"submit\" value=\"Submit\">
      </form> ";  
   }
}   
?>

<html>
<head>
Email:<BR>
<?php echo $message; ?>
</head>
<body>

</body>
</html>

 

I personally hate those <<<

A correction I noticed:

 

      $message .= "
      <form method=\"post\" action=\" " . $thisfile . "\">
      <input type=\"text\" name=\"Email\" size=10>
      <input type=\"submit\" name=\"submit\" value=\"Submit\">
      </form> ";  

 

Needed the equals after the dot. Same with the heredoc.

 

      $message .= <<< EOMSG
         
      <form method="post" action="$thisfile">
      <input type="text" name="Email" size=10>
      <input type="submit" name="submit" value="Submit">
      </form>
EOMSG;

The EOMSG; must be the only thing on a line, with only a newline following the ;. Based on the posted code, there are three spaces after the ; that would need to be removed.

 

have a try like this:...

I personally hate those <<<

 

ok - i removed the spaces from the line following EMOSG; - but i still had the error. next i altered my code so that it resembled the code from dgossens and i can see

 

Email:

 

Notice: Undefined variable: message in C:\wamp\www\*\test.php on line 47

 

any other suggestions? (here is the code just in case i did something incorrectly.

 

<?php

if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
   if (!isset($_POST['Email']) || $_POST['Email'] =="")
      $message = '<P>There is a problem with your email address</P>';    
   
   else
   {
      mysql_connect("localhost", "X", "Y") or die("Failure to communicate with database");
      mysql_select_db("X");
      
      $as_email = mysql_real_escape_string($_POST['Email']);
      $tr_email = trim($as_email);
      $query = "INSERT INTO X(ID, Email) VALUES(NULL, '$tr_email')"; 
      
      $result = mysql_query($query);
      
      if(mysql_affected_rows() == 1)
      {
         $message = '<P>Your information has been recorded.</P>';
         $noform_var = 1;
      } 
      
      else
      {
         error_log(mysql_error());
         $message = '<P>ERROR</P>';
      }            
   }      

   if (!isset($noform_var))
   {      
      $thisfile="test.php";
      $message ."
      <form method=\"post\" action=\" " . $thisfile . "\">
      <input type=\"text\" name=\"Email\" size=10>
      <input type=\"submit\" name=\"submit\" value=\"Submit\">
      </form> ";  
   }
}   
?>

<html>
<head>
Email:<BR>
<?php echo $message; ?>
</head>
<body>

</body>
</html>

 

...as i was posting this, premiso chimed in... i followed his suggestions...

 

<?php

if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
if (!isset($_POST['Email']) || $_POST['Email'] =="")
	$message = '<P>There is a problem with your email address</P>';	 

else
{
	mysql_connect("localhost", "X", "Y") or die("Failure to communicate with database");
	mysql_select_db("X");

	$as_email = mysql_real_escape_string($_POST['Email']);
	$tr_email = trim($as_email);
	$query = "INSERT INTO X(ID, Email) VALUES(NULL, '$tr_email')"; 

	$result = mysql_query($query);

	if(mysql_affected_rows() == 1)
	{
		$message = '<P>Your information has been recorded.</P>';
		$noform_var = 1;
	} 

	else
	{
		error_log(mysql_error());
		$message = '<P>ERROR</P>';
	}			   
}		

if (!isset($noform_var))
{		
	$thisfile="test.php";
	$message .=<<< EOMSG

	<form method="post" action="$thisfile">
	<input type="text" name="Email" size=10>
	<input type="submit" name="submit" value="Submit">
	</form>
EOMSG;	
}
}	
?>

<html>
<head>
Email:<BR> 
<?php echo $message; ?>
</head>
<body>

</body>
</html> 

 

...and i get Parse error: parse error in C:\wamp\www\*\test.php on line 54

 

...any other suggestions? or did i make a mistake in implementing the suggestions?...

You implemented the heredoc wrong again. I would suggest reading up on it.

 

      $message .= <<<EOMSG
         
      <form method="post" action="{$thisfile}">
      <input type="text" name="Email" size=10>
      <input type="submit" name="submit" value="Submit">
      </form>
EOMSG;

 

Heredoc is very particular on spacing, notice the space between the .= and the <<< ALso notice you have a space after the <<< and before the EOMSG which there should not be.

 

Also the note of the 3 sapces after the ; after the EOMSG, that needs to be removed as well. If you want to use heredoc you have to be precise.

 

For the undefined notice:

if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
   $message = "";
   if (!isset($_POST['Email']) || $_POST['Email'] =="")
      $message = '<P>There is a problem with your email address</P>';

 

 

 

You implemented the heredoc wrong again. I would suggest reading up on it.

 

      $message .= <<<EOMSG
        
     <form method="post" action="{$thisfile}">
     <input type="text" name="Email" size=10>
     <input type="submit" name="submit" value="Submit">
     </form>
EOMSG;

 

Heredoc is very particular on spacing, notice the space between the .= and the <<< ALso notice you have a space after the <<< and before the EOMSG which there should not be.

 

Also the note of the 3 sapces after the ; after the EOMSG, that needs to be removed as well. If you want to use heredoc you have to be precise.

 

For the undefined notice:

if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
  $message = "";
  if (!isset($_POST['Email']) || $_POST['Email'] =="")
     $message = '<P>There is a problem with your email address</P>';

 

sigh. ok, made some changes....

 

<?php
if (isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
$message = "";
if (!isset($_POST['Email']) || $_POST['Email'] =="")
	$message = '<P>There is a problem with your email address</P>';	 

else
{
	mysql_connect("localhost", "X", "Y") or die("Failure to communicate with database");
	mysql_select_db("X");

	$as_email = mysql_real_escape_string($_POST['Email']);
	$tr_email = trim($as_email);
	$query = "INSERT INTO X(ID, Email) VALUES(NULL, '$tr_email')"; 

	$result = mysql_query($query);

	if(mysql_affected_rows() == 1)
	{
		$message = '<P>Your information has been recorded.</P>';
		$noform_var = 1;
	} 

	else
	{
		error_log(mysql_error());
		$message = '<P>ERROR</P>';
	}			   
}		

if (!isset($noform_var))
{		
	$thisfile="test.php";
	$message .= <<<EOMSG

<form method="post" action="{$thisfile}">
<input type="text" name="Email" size=10>
<input type="submit" name="submit" value="Submit">
</form>
EOMSG;
}
}	
?>

<html>
<head>
Email:<BR> 
<?php echo $message; ?>
</head>
<body>

</body>
</html> 

 

and i get....

Email:

 

Notice: Undefined variable: message in C:\wamp\www\*\test.php on line 49

 

i also tried adding an empty line after EOMSG; to no avail.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.