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 <<
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