johnnycabbage
01-08-2012, 12:49 AM
I have a comment script, with a captcha before proceeding. I keep getting the error "Parse error: syntax error, unexpected '[', expecting T_PAAMAYIM_NEKUDOTAYIM in /index.php on line 11", which is beyond my knowledge of why it's occurring. Does anyone notice the error I've made? I understand the output string for "code" doesn't actually get posted, but I don't see why that would cause any issues.
<html>
<head><link rel="stylesheet" type="text/css" href="comments.css"/>
<title>Comment</title>
</head>
<body>
<?php
$act = $_POST['act'];
if($act == "post") {
$name = $_POST['name'];
$message = $_POST ['message'];
$code = &_POST ['code'];
@$fp = fopen("comments.html", 'a');
if (!$fp) {
//The file could not be opened
echo "There was an error! Please try again later!";
exit;
} else {
if (strtolower($_POST['code']) != 'mycode') {
echo "password wrong";
exit;
} else {
//The file was successfully opened, lets write the comment to it.
$outputstring = "<div id=comment1><br>Name: " .$name. "<br> Comment:<br><h4>" .$message. "</h4><br></div>";
//Write to the file
fwrite($fp, $outputstring, strlen($outputstring));
//We are finished writing, close the file for security / memory management purposes
fclose($fp);
//Post the success message
echo "Your post was successfully entered. Click <a href='index.php'>here</a> to continue.";
}
} else {
//We are not trying to post a comment, show the form.
?>
<h2>Previous comments:</h2>
<?php include("comments.html"); ?>
<br><br>
<h2>Post a comment:</h2>
<form action="index.php" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" value=""></input></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name="message"></textarea></td>
</tr>
</table>
<input type="hidden" name="act" value="post"></input>
<input type="submit" name="submit" value="Submit"></input>
Access code: <input type="text" name="code" /><br />
Please enter <b>MYCODE</b> above.
</form>
<?php
}
?>
</body>
</html>
<html>
<head><link rel="stylesheet" type="text/css" href="comments.css"/>
<title>Comment</title>
</head>
<body>
<?php
$act = $_POST['act'];
if($act == "post") {
$name = $_POST['name'];
$message = $_POST ['message'];
$code = &_POST ['code'];
@$fp = fopen("comments.html", 'a');
if (!$fp) {
//The file could not be opened
echo "There was an error! Please try again later!";
exit;
} else {
if (strtolower($_POST['code']) != 'mycode') {
echo "password wrong";
exit;
} else {
//The file was successfully opened, lets write the comment to it.
$outputstring = "<div id=comment1><br>Name: " .$name. "<br> Comment:<br><h4>" .$message. "</h4><br></div>";
//Write to the file
fwrite($fp, $outputstring, strlen($outputstring));
//We are finished writing, close the file for security / memory management purposes
fclose($fp);
//Post the success message
echo "Your post was successfully entered. Click <a href='index.php'>here</a> to continue.";
}
} else {
//We are not trying to post a comment, show the form.
?>
<h2>Previous comments:</h2>
<?php include("comments.html"); ?>
<br><br>
<h2>Post a comment:</h2>
<form action="index.php" method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" value=""></input></td>
</tr>
<tr>
<td>Comment:</td>
<td><textarea name="message"></textarea></td>
</tr>
</table>
<input type="hidden" name="act" value="post"></input>
<input type="submit" name="submit" value="Submit"></input>
Access code: <input type="text" name="code" /><br />
Please enter <b>MYCODE</b> above.
</form>
<?php
}
?>
</body>
</html>