Friday, July 13, 2018

php - syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING





I have been staring at this code for hours now and I cannot figure out where my mistake is. I know this syntax error usually comes up because of some missing or out of place curly brace or some issue with single/double quotes and I'm not sure there is one anywhere in my code. I am only trying to fix my syntax right now so I can get the code to completely compile. Any help would be much appreciated. Here is my code:



"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


Add to and Read from the Database





function print_form() {
echo <<


Please put your comments below.




Name:




Comment:






END;

}
function process_form() {


print "

adding comment...

";

$Name = $_POST['WholeName'];
$Comment = $_POST['Comment'];

if( preg_match("^[a-zA-Z]+$", $Name)) {
if( preg_match("^[a-zA-Z0-9]_\-\'[.?!]+$", $Comment)) {
$sql = "insert into comments1 values (
'$Name',

'$Comment')";
$result = mysql_query($sql) or die("Mysql query failed");
} else {
print "invalid name";
}
} else {
print "invalid characters";
}

}


$db = mysql_connect("", "", "");
if (!$db) {
print "Error - Could not connect to mysql";
exit;
}

$er = mysql_select_db("");
if (!$er) {
print "Error - Could not connect to comments1 database";

exit;
}

if (isset($_POST['stage']) && ('process' == $_POST['stage'])) {
process_form();
} else {
print_form();
}

?>





Answer



Your problem is that you're not closing your HEREDOC correctly. The line containing END; must not contain any whitespace afterwards.


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...