thank you for your patients in this i'm sure you get newbies like me all the time I'm more of an admin than a programmer... i'm trying to break into programming more and more though... first semester java at University of Cincinnati

"Premature end of script headers: php-script" is the script error according to the log.

so the form1.php file now looks like this.
form1.php

<html>
<body>
<?php
$filename = 'form1.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
?>
<?php
file_put_contents("form1.txt", array($POST['id'], $POST['email']));
// file_put_contents("form1.txt", array($POST['id'], $POST['email']));

?>

</body>
</html>

i no longer get the internal server error, and the return doesn't display anything, which i expecting to see either the file is or is not writable line but it's not doing that either...

so, is there possibly something wrong in the html?
form1.html

<html>
<head>
<title>testing</title>
</head>
<body>
<form id="form1" action="form1.php" method="post">

	ID:
	<input type="text" name="id" value="ID" />
	<br />
	Email:
	<input type="text" name="email" value="email" />
	<br />
	<input type="submit" value="Submit your application" />
</form>

</body>
</html>

    The html looks ok, and so does the php. I may be missing something, but it should be echoing one of the lines.

    Your file-writing code is outside the "if" block, so it will try to write in either case. Move that code to the same clause as "file is writable".

      [Tue Jul 18 07:50:15 2006] [error] [client <MY IP>] Premature end of script headers: php-script, referer: http://www.mindimaging.com/form1/form1.html

      seems like it's in the html, but i can't see anything wrong with this...

      form1.html
      <html>
      <body>
      	<form id="form1" action="form1.php" method="post">
      
      	ID:
      	<input type="text" name="id" value="ID" />
      	<br />
      	Email:
      	<input type="text" name="email" value="email" />
      	<br />
      	<input type="submit" value="Submit your application" />
      </form>
      
      </body>
      </html>
      ---------------------------------------------------------------
      form1.php
      <html>
      <body>
      <?php
      $filename = 'form1.txt';
      if (is_writable($filename)) {
         echo 'The file is writable';
         file_put_contents("form1.txt", array($_POST['id'], $_POST['email']));
      } else {
         echo 'The file is not writable';
      }
      ?> 
      
      </body>
      </html>
       

        This short article might shed some light (it didn't for me 🙂). Also, just a stab, check the mime type settings in your server configs.

          <meta http-equiv="Content-Type" content="text/html\n\n; charset=iso-8859-1"> was added into a header for the form1.php file.

          Request, can you try these two files on your server, and tell me if it freakin works?

            Get the '\n\n' out of there:

            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

              It works fine for me, on both Windows and Linux.

                could someone try this stupid code, i swear this shouldn't be this troublesome.

                  if that's the case then i must have a configuration issue on the server? would that be your assumption?

                    Man, you edit fast...

                    I would assume a config problem, yes. Maybe someone else can help you better with that.

                      odd that this code works

                      <html>
                      <body>
                      
                      
                      <form action="action.php" method="post">
                       <p>Your name: <input type="text" name="name" /></p>
                       <p>Your age: <input type="text" name="age" /></p>
                       <p><input type="submit" /></p>
                      </form>
                      </body>
                      </html>
                      
                      <html>
                      <body>
                      <p>
                      Hi <?php echo $_POST['name']; ?>.
                      You are <?php echo $_POST['age']; ?> years old
                      </p> 
                      </body>
                      </html>
                      
                      

                        does this possibly mean that I was wrong with my version of php? I was told that the host provider had version 5 so that line

                        file_put_contents('form1.txt', array($POST['id'], $POST['email']));

                        wouldn't work... I hate inaccurate people who tell me one thing when it's really another... why would the admin for my hosting company not know the stupid version.

                        GRRR...

                          Hi,

                          you can check the php version yourself easily by creating a short script that just contains

                          <?PHP
                          phpinfo();
                          ?>
                          

                          This script will print a table with detailed information about the installed php version (I think in your case you have a CGI PHP setup). Please save that page to a file and post the file as attachment.

                          To check if file_put_contents exists

                          <?PHP
                          if (function_exists("file_put_contents")) {
                            echo "file_put_contents available";
                          } else {
                            echo "file_put_contents missing";
                          }
                          ?>
                          

                          file_put_contents became available in PHP 5.0 so the function will work if there's PHP 5 installed on the server.

                          One note aside:
                          file_put_contents overwrites existing files unless you add FILE_APPEND as third argument to the function call.

                          Thomas

                            I'll give this a try, but yeah i was reading up on the file_put_contents and saw that it needed the third argument for it...

                            is there any just as easy way for pre 5.0.*?

                              PHP Version 5.0.4

                              and it's available... why in the heck doesn't this work!?

                               
                              form.html
                              <html>
                              <head>
                              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
                              </head>
                              <body>
                              	<form id="form1" action="form1.php" method="post">
                              
                              	ID:
                              	<input type="text" name="id" value="ID" />
                              	<br />
                              	Email:
                              	<input type="text" name="email" value="email" />
                              	<br />
                              	<input type="submit" value="Submit your application" />
                              </form>
                              
                              </body>
                              </html>
                              
                              
                              form1.php CODE 
                              <html>
                              <head>
                              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
                              </head>
                              <body>
                              <p> HI </p>
                              <?php
                              $filename = "form1.txt";
                              if (is_writable($filename)) {
                                 echo "The file is writable";
                              //   file_put_contents("form1.txt", $_POST['ID'], $_POST['email'], FILE_APPEND);
                              } else {
                                 echo "The file is not writable";
                              }
                              ?> 
                              
                              </body>
                              </html>

                                Please post the output of the phpinfo script (as attachment to your post). I'll check the settings because it seems like PHP being installed as CGI binary so some safe_mode restrictions might be the reason for your problems.

                                Do you have access to the apache error_log ? There should be entries in the error_log about the reason(s) for the internal errors.

                                Thomas

                                  Add the following lines on top of your script (above the <html> tag)

                                  <?PHP
                                  ini_set("display_startup_errors","On");
                                  ini_set("display_errors","On");
                                  ?>
                                  

                                  These settings are set to off on your server so I hope that setting these values to On will prevent the premature end errors and display something useful instead.

                                  Thomas