Look at the error message:

Parse error: parse error, unexpected ')' in process.php on line 18

As you can see the ")" is not expected there - blocks of code are opened and closed with "{" and "}". So put "}" instead of ")" in line 18.
Other then that $flat_file is not defined in your php script. It should contain local path to file where you want to store your data e.g.

$flat_file = '/home/user/form_data.txt';//linux
$flat_file = 'c:/www/user/form_data.txt';//windows

And the last thing: you don't use those hidden inputs at the beginning of a form, so you can ommit them as well.

    wilku-

    Now I get an error about line 9. Line 9 in the file is:


    if (strpos($_POST['email']) !== false) {

    I updated the 'process.php' file to:


    <?php
    if (isset($POST['newsletter'])&&$POST['newsletter']=="checkbox")
    {
    $name_arr = explode($POST['FullName']);
    $first_name = $name_arr[0];
    $file_arr = file($flat_file = 'form_data.txt'');
    $found = false;
    foreach ($file_arr as $value) {
    if (strpos($
    POST['email']) !== false) {
    $found = true;
    break;
    }
    }
    if (!$found) {
    $fp = fopen($flat_file, 'a');
    $fwrite($fp,$POST['email'] . ',' . $POST['FullName'] . "\n");
    fclose($fp);
    }
    }

    ?>

    Thanks!

      This line causes that error:

      $file_arr = file($flat_file = 'form_data.txt'');

      You open with a single quote and close with a double. Or is that two singles? (Use the forum php tags and we could tell better.)

        Installer-

        Ok, everything is fixed and the form is working without errors. However, these items are not working:


        1. Form is not redirected to the thank you page
        2. Form results (email, name) is not written to the form_data.html file
        3. Form results are not emailed to (quiz@shapefit.com)
          --------------------------------------------------------

        How can I get these actions to work with the form?

        Thanks!

          Originally posted by bad959fl

          Installer-


          1. Form is not redirected to the thank you page
          2. Form results (email, name) is not written to the form_data.html file
          3. Form results are not emailed to (quiz@shapefit.com)
            --------------------------------------------------------

          How can I get these actions to work with the form? [/B]

          I suggest process.php do it in this order:
          1. fwrite email,name in 'form_data.txt' (I guess you do not mean .html)
          2. mail() function is used to send results to shapefit mailbox
          3. Redirect or just a simple echo 'Thank you. We have recorded your data. You will get an email from us';
          You can add echo "<a href='home.php'>Back home</a>";

          1. fwrite, is already there. Should only be fixed so it works.
          2. go learn howto use mail() function
            http://php.net/mail ->See all examples in comments

          Also this thread is example code of howto send mail:
          http://www.phpbuilder.com/board/showthread.php?threadid=10302808

            Hey guys,

            I made a few changes to the form below to forward to a thank you page but I'm getting an error. Its also not posting the email and name to the subscribers.txt file. Any thoughts?

            <?php
            if (isset($POST['newsletter'])&&$POST['newsletter']=="checkbox")
            {
            $name_arr = explode($POST['FullName']);
            $first_name = $name_arr[0];
            $file_arr = file($flat_file = 'subscribers.txt');
            $found = false;
            foreach ($file_arr as $value) {
            if (strpos($
            POST['email']) !== false) {
            $found = true;
            break;
            }
            }
            if (!$found) {
            $fp = fopen($flat_file, 'a');
            $fwrite($fp,$POST['email'] . ',' . $POST['FullName'] . "\n");
            fclose($fp);
            else $URL="http://shapefit.com/thankyou-newsletter.html";header ("Location: $URL");
            }
            }
            ?>

              halojoy,

              I just found this test php script and it seems to write to the file and redirect fine. However, its not checking for the "newsletter" checkbox before writing to the file.

              <?php
              $emailAddress = $_POST['email'];

              if (isset($POST['newsletter'])&&$POST['newsletter']=="checkbox")
              {
              echo "Please enter your email address.";
              exit;
              }
              else
              {
              $filename = "subscribers.txt"; // File which holds all data
              $content = "$emailAddress\n"; // Content to write in the data file
              $fp = fopen($filename, "a"); // Open the data file, file points at the end of file
              $fw = fwrite( $fp, $content ); // Write the content on the file
              fclose( $fp ); // Close the file after writing

              if(!$fw) echo "Couldn't write the entry.";
              else $URL="http://shapefit.com/thankyou-newsletter.html";header ("Location: $URL");

              }
              ?>

                Put [php][/php] tags around your PHP code.
                Will give those colors.

                  halojoy-

                  Bare with me here, I'm definitely a newbie with the php stuff 🙂

                  Do you have any specific advice for helping me with this?

                  Thanks!

                    I actually fix that a while ago. Here is the code in the form:

                    <input type="checkbox" name="newsletter" value="newsletter" checked>

                    This is correct, right?

                      Can you not figure out how to post highlighted code? If not, say so, and someone will explain it to you.

                        Is this correct?

                        <?php
                        if (isset($_POST['newsletter'])&&$_POST['newsletter']=="checkbox")
                        {
                        $name_arr = explode($_POST['FullName']);
                        $first_name = $name_arr[0];
                        $file_arr = file($subscribers.txt);
                        $found = false;
                        foreach ($file_arr as $value) {
                        if (strpos($_POST['email']) !== false) {
                        $found = true;
                        break;
                        }
                        }
                        if (!$found) {
                        $fp = fopen($subscribers.txt, 'a');
                        $fwrite($fp,$_POST['email'] . ',' . $_POST['FullName'] . "\n");
                        fclose($fp);
                        }
                        }
                        else $URL="http://shapefit.com/thankyou-newsletter.html";header ("Location: $URL");
                        ?>
                        

                          I believe it should be:

                          if  (isset($_POST['newsletter']) && ($_POST['newsletter']=="newsletter")) 

                            Installer-

                            Just updated, but its still not writing to file...

                              I think $found is not working alright

                              $file_arr = file($subscribers.txt); 
                              $found = false; 
                              foreach ($file_arr as $value) { 
                              
                              // this line might need a change
                              if (strpos($_POST['email']) !== false) { 
                              
                              $found = true; 
                              break; 
                              } 
                              } 
                              if (!$found) { 
                              $fp = fopen($subscribers.txt, 'a');
                              // ...
                              }

                                Here are the latest errors:


                                Warning: Wrong parameter count for explode() in new.php on line 4

                                Warning: file(txt): failed to open stream: No such file or directory in new.php on line 6

                                Warning: Invalid argument supplied for foreach() in new.php on line 8

                                Warning: fopen(txt): failed to open stream: Permission denied in new.php on line 15

                                Fatal error: Call to undefined function: () in new.php on line 16

                                The form code is:


                                <form method="POST" action="new.php">
                                <input type=hidden name="recipient" value="quiz@shapefit.com">
                                <input type=hidden name="subject" value="Fitness I.Q. Quiz Entry">
                                <input type=hidden name="print_config" value="email,subject">
                                <input type=hidden name="redirect"value="http://www.shapefit.com/thankyou-quiz.html">
                                <input type=hidden name="env_report" value="REMOTE_HOST, HTTP_USER_AGENT">
                                <input type=hidden name="required" value="FullName,email,Referred By">
                                <div align="center">

                                <p><br>
                                Full Name&nbsp;&nbsp; <br>
                                <input type="text" name="FullName" size="25">
                                </p>
                                <p>
                                Email Address:<br>
                                <input type="text" name="email" size="25">
                                </p>
                                <p>How did you find us?<br>
                                <input type="text" name="Referred By" size="25">
                                </p>
                                <p>
                                If you found us through a search <br>
                                engine, what were you searching for?<br>
                                <input type="text" name="Searching For" size="25">
                                </p>
                                <p>

                                <input type="checkbox" name="newsletter" value="newsletter" checked>
                                Yes, I would like to sign up for your <b>FREE</b> newsletter!<br>
                                <br>
                                <br>
                                <input name="subscribe" type="image" alt="fitness quizzes" src="http://www.shapefit.com/start-quiz2.gif">
                                </p>
                                </div>

                                </form>

                                The php code is:

                                <?php 
                                if  (isset($_POST['newsletter']) && ($_POST['newsletter']=="newsletter"))
                                { 
                                $name_arr = explode($_POST['FullName']);
                                $first_name = $name_arr[0]; 
                                $file_arr = file($subscribers.txt);
                                $found = false; 
                                foreach ($file_arr as $value) { 
                                if (strpos($_POST['email']) !== false) { 
                                $found = true; 
                                break; 
                                } 
                                } 
                                if (!$found) { 
                                $fp = fopen($subscribers.txt, 'a'); 
                                $fwrite($fp,$_POST['email'] . ',' . $_POST['FullName'] . "\n"); 
                                fclose($fp);  
                                } } else $URL="http://shapefit.com/thankyou-newsletter.html";header ("Location: $URL"); ?>
                                  if (strpos($_POST['email'])

                                  You're missing a parameter in the strpos() argument; you don't tell it what substring to look for.

                                    // $subscribers.txt
                                    // either you use
                                    $filename = 'subscribers.txt';
                                    // and put in $filename
                                    
                                    // or you just put in 'subscribers.txt'
                                    // where this file is refered to

                                      Like this:

                                      $file_arr = 'subscribers.txt');