Jump to content

Getting an error and can't find the problem


RichG

Recommended Posts

Hi

 

I am getting this error when i load my page.

 

Parse error: syntax error, unexpected $end in /homepages/12/d235019564/htdocs/phptest/ssf.php on line 70

 

This is my code and I have checked it against the example in the book and I can't see the problem anywhere. Can anyone see what i am missing.

 

<?php
if ($_POST['submit'] == 'submit') 
{
	if (!$_POST['email'] || $_POST['email'] == "" || strlen($_POST['email'] >30)) 
	{
		$message = '<p>There was a problem. Did you enter an email address?</p>';
	}
	else 
	{
	// Open connection to database
		mysql_connect('xxxx', 'xxxx', 'xxxx') 
			or die("faliure to connect with database");
		mysql_select_db('xxxx');

			//Insert email address
				$as_email = addslashes($_POST['email']);
				$tr_email = trim($as_email);
				$query = "INSERT INTO `mailinglist` VALUES ('{NULL}', '{$tr_email}', '{www.example.com}')";

				$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>Something went wrong with your signup attempt.</p>';
						}
					}

			//Show the form in every case except succesful submission
				if (!$noform_var)
					{
					$thisfile = $_SERVER['PHP_SELF'];
					$message .= <<< EOMSG
				<p>Enter your email address and we will send you our weekly newsletter.</p>
				<FORM METHOD="post" ACTION="$thisfile">
				<INPUT TYPE="text" SIZE="25" NAME="email">
				<BR><BR>
				<INPUT TYPE="submit" NAME="submit" VALUE="submit">
				</FORM>
				EOMSG;
				}
			}
			?>
<html>
<head>
<STYLE TYPE="text/css">
<!--
BODY. P	{color:black; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px}
H1		{color:black; font-family:Arial, Helvetica, sans-serif; font-size:12px}
-->
</STYLE>
</head>
<body>
<table border="0" cellpadding="10" width="100%">
<tr>
    	<td bgcolor="#f0f8ff" align="center" valign="top" width="17%"></td>
        <td bgcolor="#FFFFFF" align="left" valign="top" width="83%"><H1>Newsletter Sign-up form</H1>
        <?php
	 echo $message;
	 ?>
        </td>
    </tr>
</table>
</body>
</html><---- Line 70

 

Cheers

RichG

Link to comment
Share on other sites

I have gone through the whole file and there are exactly the right amount of {} and ().

 

I did however notice that the

 

<<<EOMSG
EOMSG;

 

are differnet colours in this post. Could the error be in that block of code. I also noticed that in my dreamweaver document the 'and' in the "//Show the form in every case except succesful submission" code is blue so is being picked up as php code.

 

Could someone tell me if this should be happening?

 

Cheers

RichG

Link to comment
Share on other sites

OK

 

That worked

 

Got the page up now but not seeing my <?php echo $message ?> in my table. The rest is there but not code form line 58

 

<?php
if ($_POST['submit'] == 'submit') 
{
	if (!$_POST['email'] || $_POST['email'] == "" || strlen($_POST['email'] >30)) 
	{
		$message = '<p>There was a problem. Did you enter an email address?</p>';
	}
	else 
	{
	// Open connection to database
		mysql_connect('db1341.oneandone.co.uk', 'dbo235515377', '2X5V6hgS') 
			or die("faliure to connect with database");
		mysql_select_db('db235515377');

			//Insert email address
				$as_email = addslashes($_POST['email']);
				$tr_email = trim($as_email);
				$query = "INSERT INTO `mailinglist` VALUES ('{NULL}', '{$tr_email}', '{www.example.com}')";

				$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>Something went wrong with your signup attempt.</p>';
						}
					}

			//Show the form in every case except succesful submission
				if (!$noform_var)
					{
					$thisfile = $_SERVER['PHP_SELF'];
					$message .= <<<EOMSG
					<p>Enter your email address so we can send you our weekly newsletter.</p>
					<FORM METHOD="post" ACTION="$thisfile">
					<INPUT TYPE="text" SIZE=25 NAME="email">
					<BR><BR>
					<INPUT TYPE="submit" NAME="submit" VALUE="submit">
					</FORM>
EOMSG;
				}
			}
			?>
<html>
<head>
</head>
<body>
<table border="1" cellpadding="10" width="100%">
<tr>
    	<td bgcolor="#f0f8ff" align="center" valign="top" width="17%"></td>
        <td bgcolor="#FFFFFF" align="left" valign="top" width="83%">
        <H1>Newsletter Sign-up form</H1>
    	<?php echo $message; ?>
        </td>
    </tr>
</table>
</body>
</html>

 

the page is www.richdgrimes.co.uk/phptest/ssf.php so you can see the result.

 

Cheers

RichG

Link to comment
Share on other sites

need to move one of your bracket up.

<?php
if ($_POST['submit'] == 'submit')
{
  if (!$_POST['email'] || $_POST['email'] == "" || strlen($_POST['email'] >30))
{
$message = '<p>There was a problem. Did you enter an email address?</p>';
}
else
{
// Open connection to database
mysql_connect('db1341.oneandone.co.uk', 'dbo235515377', '2X5V6hgS')or die("faliure to connect with database");
mysql_select_db('db235515377');
  //Insert email address
$as_email = addslashes($_POST['email']);
$tr_email = trim($as_email);
$query = "INSERT INTO `mailinglist` VALUES ('{NULL}', '{$tr_email}', '{www.example.com}')";
  $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>Something went wrong with your signup attempt.</p>';
  }
  }
} // this bracket was below which meant submit had to be pressed in order to show the form
//Show the form in every case except succesful submission
if (!$noform_var)
{
$thisfile = $_SERVER['PHP_SELF'];
$message .= <<<EOMSG
					<p>Enter your email address so we can send you our weekly newsletter.</p>
					<FORM METHOD="post" ACTION="$thisfile">
					<INPUT TYPE="text" SIZE=25 NAME="email">
					<BR><BR>
					<INPUT TYPE="submit" NAME="submit" VALUE="submit">
					</FORM>
EOMSG;
				}
			?>
<html>
<head>
</head>
<body>
<table border="1" cellpadding="10" width="100%">
<tr>
    	<td bgcolor="#f0f8ff" align="center" valign="top" width="17%"></td>
        <td bgcolor="#FFFFFF" align="left" valign="top" width="83%">
        <H1>Newsletter Sign-up form</H1>
    	<?php echo $message; ?>
        </td>
    </tr>
</table>
</body>
</html>

 

Ray

Link to comment
Share on other sites

don't you just love it when you buy a book for £30 and it has the wrong cod in it  ???.

 

I am doing another page now as the page now works.

 

Thanks Everyone

 

$rate_form = <<< EORATEFORM

<p>My boss is</p>

<form method="post" action="$thisfile">

<input type="radio" name="rating" value=1>

Driving me to look for a new job.<br>

<input type="radio" name="rating" value=2>

Not the worst. But pretty bad.<br>

<input type="radio" name="rating" value=3>

Just so-so.<br>

<input type="radio" name="rating" value=4>

Pretty good.<br>

<input type="radio" name="rating" value=5>

A pleasure to work with.<br><br>

Boss's name: <input type="text" size=25 name="boss"><br> (this text has gone red after the ' in boss's is this ok)

 

Cheers

RichG

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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