Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Comment and captcha script error

    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.
    PHP Code:
    <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$outputstringstrlen($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>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    remove all spaces you have between $_POST and [

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

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,343
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Also look at this on line 11:
    $code = &_POST ['code'];

    That & should be $
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    good eye ... I missed that one.

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,343
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    41
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    <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$outputstringstrlen($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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •