errcricket Posted March 20, 2009 Share Posted March 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/ Share on other sites More sharing options...
dgoosens Posted March 20, 2009 Share Posted March 20, 2009 remove all the space in front of EOMSG; and it should work Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789571 Share on other sites More sharing options...
errcricket Posted March 20, 2009 Author Share Posted March 20, 2009 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; } } . . Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789573 Share on other sites More sharing options...
dgoosens Posted March 20, 2009 Share Posted March 20, 2009 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 <<< Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789574 Share on other sites More sharing options...
PFMaBiSmAd Posted March 20, 2009 Share Posted March 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789576 Share on other sites More sharing options...
dgoosens Posted March 20, 2009 Share Posted March 20, 2009 as he ^ said... that's why I hate those things Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789578 Share on other sites More sharing options...
premiso Posted March 20, 2009 Share Posted March 20, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789582 Share on other sites More sharing options...
errcricket Posted March 20, 2009 Author Share Posted March 20, 2009 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?... Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789587 Share on other sites More sharing options...
dgoosens Posted March 20, 2009 Share Posted March 20, 2009 yeah... you forgot to remove the extra blank spaces behind EOMSG; and to add an empty line... Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789592 Share on other sites More sharing options...
premiso Posted March 20, 2009 Share Posted March 20, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789595 Share on other sites More sharing options...
errcricket Posted March 20, 2009 Author Share Posted March 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789624 Share on other sites More sharing options...
premiso Posted March 20, 2009 Share Posted March 20, 2009 $message = ""; if (isset($_POST['submit']) && $_POST['submit'] == 'Submit') { Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789626 Share on other sites More sharing options...
errcricket Posted March 20, 2009 Author Share Posted March 20, 2009 $message = ""; if (isset($_POST['submit']) && $_POST['submit'] == 'Submit') { bang premiso. errors are gone thanks to everyone who posted solutions. ...and the learning continues.... Quote Link to comment https://forums.phpfreaks.com/topic/150344-solved-parse-error-parse-error-in-cwampwwwtestphp-on-line-55/#findComment-789631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.