Basically I'm trying to get the post data from my form page to link back to my php page and it won't post for whatever reason. I've been scrutinizing my code and looking online at other posts but have had no luck.

My html form:

<form id="form1" name="form1" method="post" action="anthonyBook.php">
  <p>
    <label for="name">name</label>
    <input type="text" name="name" id="name" />
  </p>
  <p>
    <label for="email">email</label>
    <input type="text" name="email" id="email" />
  </p>
  <p>
    <label>comments
      <input type="text" name="comments" id="comments" />
    </label>
  </p>
  <p> 
    <input type="submit" name="submit" id="submit" value="Submit" />
  </p>
</form>

My php page:

<?php
echo '<a href="form1.html">sign my guest book</a>';

$guestbook = @fopen("sign.txt", "r");
    while (!feof($guestbook)) 
        {
            echo "\n" . @fgets($guestbook) . "<br />";
        }
@fclose($guestbook);

$datetime=date("y-m-d h:i:s");
$data = "<h1>" . $datetime . " \n" . $_POST['name'] . " \n" . $_POST['email'] . " \n" . $_POST['comments'] . "</br></h1>";

$guestbook = @fopen("sign.txt", "w");
echo @fputs($guestbook, $data);
@fclose($guestbook);
?>

Any help is appreciated

its probably the file functions?

Take out the @ symbols - they suppress errors

My php page:

<?php
echo '<a href="form1.html">sign my guest book</a>';
$guestbook = fopen("sign.txt", "r");
    while (!feof($guestbook)) 
        {
            echo "\n" . fgets($guestbook) . "<br />";
        }
fclose($guestbook);
$datetime=date("y-m-d h:i:s");
$data = "<h1>" . $datetime . " \n" . $_POST['name'] . " \n" . $_POST['email'] . " \n" . $_POST['comments'] . "</br></h1>";
$guestbook = fopen("sign.txt", "w");
echo fputs($guestbook, $data);
fclose($guestbook);
?>

symbols - they suppress errors

When I have taken out the @ symbols i have more errors, see i'm using a certain server which i have no access to the server's php.ini file and don't know its configuration

If you don't know the configuration, put up a simple page that will display the information for you

<?php
phpinfo();
?>

That's all you need.

What are the errors?

Take out the file functions for now and see if the data posts to the page:

<?php
echo '<a href="form1.html">sign my guest book</a>';
//$guestbook = fopen("sign.txt", "r");
//    while (!feof($guestbook)) 
//        {
//            echo "\n" . fgets($guestbook) . "<br />";
//        }
//fclose($guestbook);
$datetime=date("y-m-d h:i:s");
$data = "<h1>" . $datetime . " \n" . $_POST['name'] . " \n" . $_POST['email'] . " \n" . $_POST['comments'] . "</br></h1>";
//$guestbook = fopen("sign.txt", "w");
//echo fputs($guestbook, $data);
//fclose($guestbook);
echo $data;
?>

phpinfo(); that coder mentioned above will tell you the local address of the current file(in the huge list of info under server vars), so you can link to the direct file eg: "c://vhosts/inetpub/example.com/httpdocs/sign.txt" or something like that - if it says php doesnt have permission to open/write the file you need to contact the hosting provider and tell them you need php to be able to write/open/append files

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.