RichG Posted March 6, 2008 Share Posted March 6, 2008 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 https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/ Share on other sites More sharing options...
revraz Posted March 6, 2008 Share Posted March 6, 2008 You are more than likely missing a } or ) closing bracket somewhere. Link to comment https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-484936 Share on other sites More sharing options...
RichG Posted March 6, 2008 Author Share Posted March 6, 2008 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 https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-484947 Share on other sites More sharing options...
revraz Posted March 6, 2008 Share Posted March 6, 2008 EOMSG; needs to be the ONLY thing on that line, don't even have spaces before it. Link to comment https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-484972 Share on other sites More sharing options...
RichG Posted March 6, 2008 Author Share Posted March 6, 2008 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 https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-485361 Share on other sites More sharing options...
BlueSkyIS Posted March 6, 2008 Share Posted March 6, 2008 you see no message because this is not true: $_POST['submit'] == 'submit' Link to comment https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-485376 Share on other sites More sharing options...
RichG Posted March 6, 2008 Author Share Posted March 6, 2008 Why not I have copied the code straight from the book. Is the book wrong? RichG Link to comment https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-485384 Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 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 https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-485392 Share on other sites More sharing options...
RichG Posted March 6, 2008 Author Share Posted March 6, 2008 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 https://forums.phpfreaks.com/topic/94722-getting-an-error-and-cant-find-the-problem/#findComment-485411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.