...

View Full Version : Comment and captcha script error



johnnycabbage
01-08-2012, 01: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>

mlseim
01-08-2012, 02:08 AM
remove all spaces you have between $_POST and [

you're doing that on a few different lines. fix them all.

tangoforce
01-08-2012, 02:10 AM
Also look at this on line 11:
$code = &_POST ['code'];

That & should be $

mlseim
01-08-2012, 02:13 AM
good eye ... I missed that one.

johnnycabbage
01-08-2012, 02:16 AM
Done and done. Common typing mistake.

A new error has developed though: Parse error: syntax error, unexpected T_ELSE in /hermes/web03/b424/moo.balphazonecom1/comments/index.php on line 34

Also I think another error, is the access code input, has to be included with the other inputs. I'll get on that.

tangoforce
01-08-2012, 02:38 AM
See the coding styles link in my signature. The style of coding you're using doesn't help.

This line in your code:
if($act == "post") {

That { has no partner closing }.

Again, I found that using the tips demonstrated in my coding styles link.

johnnycabbage
01-08-2012, 02:55 AM
This coding is really rough, I'll work on that once it's actually put to use.
But yes, I managed to fix the problem. I removed the error for if the file could not be opened, as that is not much of a concern.


<html>
<head>
<title>Comment</title>
</head>
<body>
<?php
$act = $_POST['act'];
if($act == "post") {
$name = $_POST['name'];
$message = $_POST['message'];
$code = $_POST['code'];
@$fp = fopen("comments.php", 'a');
if (strtolower($_POST['code']) != 'mycode') {
//wrong password
echo "wrong password";
exit;
} else {
//The file was successfully opened, lets write the comment to it.
$outputstring = "<br>Name: " .$name. "<br> Comment:<br>" .$message. "<br>";

//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.php"); ?>
<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>
<tr>
<td>code:</td>
<td><input type="text" name="code" value=""></input></td>
</tr>
</table>
<input type="hidden" name="act" value="post"></input>
<input type="submit" name="submit" value="Submit"></input>
</form>
<?php
}
?>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum